how to enable pthreads on MAMP

≡放荡痞女 提交于 2020-01-14 03:50:42

问题


I'm using a Mac with OS X Mavericks, and running php scripts within MAMP. Some of the php scripts I'm running require the use of pthreads.

Can anyone provide step-by-step instructions on installing or enabling pthreads on a Mac?

I have Googled extensively and have found little-to-no documentation on this. All I have found is that I may or may not have to recompile php from source, or maybe just add a couple flags to php.ini, or maybe I can just use pecl, etc. In terminal, I tried pecl install pthreads and received this error:

Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user

I'm pretty much lost at this point. I want to avoid switching to my Windows machine with WAMP if possible.


回答1:


I'm not a Mac user, however the build process is the same for Mac and unix, so I can help you with that.

To configure your current installation:

Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user

This is the reason pecl install failure, maybe check the configuration for php_dir.

You can ascertain the value of the setting with:

pecl config-get php_dir

I am unfamiliar with MAMP, but it is probably the case that you do not have a Thread Safe build of PHP.

You can ascertain this with:

php -i | grep Thread

You should expect:

Thread Safety => enabled

If you have Thread Safety enabled, it should be the case that fixing the permissions on php_dir will fix your problem.

If you do not, you will have to rebuild, or install from another source, a Thread Safe build of PHP.

Building Yourself

The last option is to build yourself, since this means you will miss out on updates provided by upstream, though I'm not familiar enough to know for sure if there is a well maintained thread safe build, I will assume that there is.

To build yourself you will need to overwrite your current installation with a new one, download the sources to PHP for your desired version (5.5+ recommended, latest stable, all the time is best).

Enabled Extensions

You will want to ascertain which extensions are enabled for your current build and decide which you want to enable in your new build.

To ascertain which extensions are enabled:

php -m

Make a note of these:

php -m > enabled-extensions

Configuring the Build

To configure the build to be Thread Safe use the following configure option:

--enable-maintainer-zts

You will want to set the prefix of the new installation to match the old with:

--prefix=/old/prefix

If your current php binary is at /usr/local/bin/php, then the prefix is /usr/local. If your current php binary is at /usr/bin/php, then the prefix is /usr.

You will also want to match your current builds configuration directory and scan directory settings:

--with-config-file-path=/old/config/path

If your current php.ini is at /usr/lib/php.ini, then the path is /usr/lib If your current php.ini is at /etc/php.ini, then the path is /etc

If you are using scan directories at startup, for example, you have the directory /etc/php.d

--with-config-file-scan-dir=/etc/php.d

If your current scan directory is /etc/php.d, then the dir is /etc/php.d

To configure extensions, referencing the list you made at the beginning, use the command:

./configure --help

To figure out the switches enable your chosen extensions. If there are extensions in the list that are in pecl, you can install those after the build is complete with the pecl command.

Generally:

  • --enable-extname: no dependencies on external libraries
  • --with-extname: dependent on external libraries

Making the Build

After configure we have to run make, if you have multiple processors or cores, you might want to use multiple jobs:

make -j8

Will allow make to run in parallel (maximum of 8 jobs), this speeds up builds considerably. Use as many jobs as you have cores.

During make, if a failure occurs it will be obvious what the failure relates to, if you can spot the name of a library (usually the name of the extension that causes failure is helpful), then you can usually resolve the error by installing the development package for the library that caused the failure.

A development package contains headers and or static libraries, it is usually the case that package maintainers omit this stuff from normal packages to save weight, so you can have the libxml2 package installed but not have headers.

Installing the Build

When make completes you will have your build ready for installation, make sure you have permissions for the prefix and execute

make install

Pecl Extensions

You should now be able to install the PECL extensions that you require with

pecl install extname

pthreads

You can now install with PECL or from github:

pecl install pthreads



来源:https://stackoverflow.com/questions/22232865/how-to-enable-pthreads-on-mamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!