简体   繁体   English

如何在MAMP上启用pthread

[英]how to enable pthreads on MAMP

I'm using a Mac with OS X Mavericks, and running php scripts within MAMP. 我正在使用Mac OS X Mavericks,并在MAMP中运行php脚本。 Some of the php scripts I'm running require the use of pthreads . 我正在运行的某些php脚本要求使用pthreads

Can anyone provide step-by-step instructions on installing or enabling pthreads on a Mac? 谁能提供在Mac上安装或启用pthread的分步说明?

I have Googled extensively and have found little-to-no documentation on this. 我已经在Google上进行了广泛的搜索,并且发现了很少甚至没有相关的文档。 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: 我发现的全部是,我可能不一定必须从源代码重新编译php,或者只是将几个标志添加到php.ini,或者也许我只能使用pecl等。在终端中,我尝试了pecl install pthreads并收到了这个错误:

Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user 无法安装,当前用户无法写入通道“ pecl.php.net”的php_dir

I'm pretty much lost at this point. 此时我几乎迷路了。 I want to avoid switching to my Windows machine with WAMP if possible. 如果可能,我想避免使用WAMP切换到Windows计算机。

I'm not a Mac user, however the build process is the same for Mac and unix, so I can help you with that. 我不是Mac用户,但是Mac和UNIX的构建过程相同,因此我可以为您提供帮助。

To configure your current installation: 要配置当前安装:

Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user 无法安装,当前用户无法写入通道“ pecl.php.net”的php_dir

This is the reason pecl install failure, maybe check the configuration for php_dir. 这是pecl安装失败的原因,也许检查php_dir的配置。

You can ascertain the value of the setting with: 您可以使用以下方法确定设置的值:

pecl config-get php_dir 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. 我不熟悉MAMP,但您可能没有PHP的线程安全构建。

You can ascertain this with: 您可以使用以下方法确定此问题:

php -i | php -i | grep Thread grep线程

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. 如果启用了线程安全,则应该是在php_dir上修复权限才能解决您的问题。

If you do not, you will have to rebuild, or install from another source, a Thread Safe build of PHP. 如果不这样做,则必须重新构建或从其他来源安装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). 要构建自己,您将需要用新的安装覆盖当前安装,将源代码下载到PHP以获得所需的版本(建议使用5.5+,最新的稳定版本,始终是最好的)。

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 的PHP -M

Make a note of these: 记录以下内容:

php -m > enabled-extensions php -m> enabled-extensions

Configuring the Build 配置构建

To configure the build to be Thread Safe use the following configure option: 要将构建配置为“线程安全”,请使用以下配置选项:

--enable-maintainer-zts --enable-maintainer-zts

You will want to set the prefix of the new installation to match the old with: 您将需要设置新安装的前缀以与旧安装匹配:

--prefix=/old/prefix --prefix = /旧/前缀

If your current php binary is at /usr/local/bin/php, then the prefix is /usr/local. 如果您当前的php二进制文件位于/ usr / local / bin / php,则前缀为/ usr / local。 If your current php binary is at /usr/bin/php, then the prefix is /usr. 如果您当前的php二进制文件位于/ usr / bin / php,则前缀为/ usr。

You will also want to match your current builds configuration directory and scan directory settings: 您还需要匹配当前的构建配置目录和扫描目录设置:

--with-config-file-path=/old/config/path --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 如果您当前的php.ini位于/usr/lib/php.ini,则路径为/ usr / lib如果您当前的php.ini位于/etc/php.ini,则路径为/ etc

If you are using scan directories at startup, for example, you have the directory /etc/php.d 例如,如果在启动时使用扫描目录,则目录为/etc/php.d

--with-config-file-scan-dir=/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 如果您当前的扫描目录是/etc/php.d,则目录是/etc/php.d

To configure extensions, referencing the list you made at the beginning, use the command: 要配置扩展,请参考开始时列出的列表,请使用以下命令:

./configure --help ./configure-帮助

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. 如果列表中包含pecl中的扩展名,则可以在构建完成后使用pecl命令安装这些扩展名。

Generally: 通常:

  • --enable-extname : no dependencies on external libraries --enable-extname :不依赖外部库
  • --with-extname : dependent on external libraries --with-extname :依赖于外部库

Making the Build 进行构建

After configure we have to run make , if you have multiple processors or cores, you might want to use multiple jobs: configure我们必须运行make ,如果您有多个处理器或内核,则可能要使用多个作业:

make -j8 使-j8

Will allow make to run in parallel (maximum of 8 jobs), this speeds up builds considerably. 将允许make并行运行(最多8个作业),这大大加快了构建速度。 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. make期间,如果发生故障,则很明显与故障有关,如果您可以找到库的名称(通常会引起故障的扩展名很有用),那么通常可以通过安装库来解决错误。导致失败的库的开发包。

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. 开发软件包包含标头和/或静态库,通常情况下,软件包维护者会从常规软件包中忽略这些内容以减轻重量,因此可以安装libxml2软件包,但不安装标头。

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完成时,您将准备好要安装的构建,请确保您具有前缀权限并执行

make install 进行安装

Pecl Extensions Pecl扩展

You should now be able to install the PECL extensions that you require with 您现在应该能够安装所需的PECL扩展

pecl install extname pecl安装扩展名

pthreads 线程

You can now install with PECL or from github: 您现在可以使用PECL或从github安装:

pecl install pthreads pecl安装pthreads

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM