记一次PHP7.2+pthreads多线程环境搭建

2018-11-02 浏览:138
记一次PHP7.2+pthreads多线程环境搭建
评论:(0)复制地址

写在前面 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
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说明成功。

评论:(0)复制地址
发布:zpblog | 分类:Linux | Tags:php lnmp

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。