php7 pthreads鸡肋_PHP7.3 zts(线程安全)编译以及多线程(pthreads)使用

下载PHP

su root

mkdir tmp

cd tmp

wget https://www.php.net/distributions/php-7.3.7.tar.bz2

编译安装PHP开启线程安全

tar -jxvf php-7.3.7.tar.bz2

cd php-7.3.7

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libicu-devel

编译

./configure \

--prefix=/usr/local/php-7.3.7-ts \

--enable-maintainer-zts \

--enable-fpm \

--with-fpm-user=www \

--with-fpm-group=www \

--enable-bcmath \

--enable-exif \

--enable-intl \

--enable-mbstring \

--enable-pcntl \

--with-pdo-mysql \

--enable-sockets \

--enable-mysqlnd \

--with-gd

然后:

make && make install

更新autoconf

Autoconf version 2.68 or higher is required错误是才需要此步骤

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz

tar -zxvf autoconf-latest.tar.gz

cd autoconf-2.69/

.configure

make

make install

autoconf --version

安装pthreads

git clone https://github.com/krakjoe/pthreads.git

cd pthreads

/usr/local/php-7.3.7-ts/bin/phpize

./configure --with-php-config=/usr/local/php-7.3.7-ts/bin/php-config

make

make install

修改 /usr/local/php-7.3.7-ts/lib/php.ini,增加 extension=pthreads

测试pthreads

/usr/local/php-7.3.7-ts/bin/php worker.php

class MyWorker extends Worker

{

public $id;

public $time;

public function __construct($id, $time)

{

$this->id = $id;

$this->time = $time;

}

public function run()

{

while (true) {

echo sprintf(worker %s is running, %s\n, $this->id, date('Y-m-d H:i:s'));

sleep($this->time);

}

}

}

class MyManager

{

/**

* @var MyWorker[]

*/

protected $workers;

public function add(MyWorker $work)

{

$this->workers[$work->id] = $work;

echo 'add worker' . $work->id . \n;

}

public function run()

{

foreach ($this->workers as $id => $work) {

echo 'run worker' . $work->id . \n;

$work->start();

}

}

}

$manager = new MyManager();

$manager->add(new MyWorker('1', 1));

$manager->add(new MyWorker('2', 3));

$manager->run();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值