写在前面 pthreads v3 只能在CLI模式下运行,固按需安装,原文如下:
SAPI Support
pthreads v3 is restricted to operating in CLI only: I have spent many years trying to explain that threads in a web server just don't make sense, after 1,111 commits to pthreads I have realised that, my advice is going unheeded.
So I'm promoting the advice to hard and fast fact: you can't use pthreads safely and sensibly anywhere but CLI.
Thanks for listening ;)
https://github.com/krakjoe/pthreads/
PHP 7.2 安装
wget http://php.net/distributions/php-7.2.11.tar.gz tar xvzf php-7.2.11.tar.gz cd php-7.2.11 ./configure --prefix=/usr/local/php7 --enable-maintainer-zts --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --with-fpm-user=www --with-fpm-group=www make clean && make && make install cp php.ini-production /usr/local/php7/etc/php.ini cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm chmod 755 /etc/init.d/php7-fpm cd /usr/local/php7/etc/ cp php-fpm.conf.default php-fpm.conf cd php-fpm.d cp www.conf.default www.conf /etc/init.d/php7-fpm start
pthreads 安装
wget https://codeload.github.com/krakjoe/pthreads/zip/master unzip master cd pthreads-master /usr/local/php7/bin/phpize ./configure --with-php-config=/usr/local/php7/bin/php-config make make install
由于pthreads v3只支持cli模式,所以加入php配置文件如下:
cd /usr/local/php7/etc/ cp php.ini php-cli.ini
编辑 php-cli.ini 加入以下:
extension="pthreads.so"
查看安装是否成功
运行
/usr/local/php7/bin/php -m
查看模块支持列表,如果有pthreads存在则说明环境创建成功。
或者编辑文件pthreads.php
<?php $thread = new class extends Thread { public function run() { echo "Hello World\n"; } }; $thread->start() && $thread->join(); ?>
/usr/local/php7/bin/php -f pthreads.php
成功输出Hello World说明成功。
附:pthreads v2 支持 PHP 5.3+
最新v2版本地址:https://github.com/krakjoe/pthreads/archive/v2.0.10.zip
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
相关文章
PHP 5.3 利用suhosin禁用eval函数2019-03-01
根据PayPal通知要求,让CentOS下的Nginx支持TLS 1.22018-05-08
树莓派系列(八):PHP之以root权限执行Python GPIO脚本2016-01-16
phpExcelReader读取Excel报错解决方法2015-11-18
CentOS下为PHP安装 IMAP 扩展2015-05-26
PHP使用IMAP收取邮件并提取指定内容2015-05-26
一个PHP在线编辑服务端指定TXT文本的实例2015-04-27
一个简单php+mysql快递单号扫码记录网页2015-03-30
树莓派系列(三):WEB服务器之搭建LNMP环境2014-11-20
转:PHP配置安全检查工具 – PCC2014-09-17