搜索
系统检测到您的用户名不符合规范:

PHP7.2 安装 PThread

浏览:6075 发布日期:2018年02月24日 分类:用法示例 关键字: PThread
通过本篇,能学会如何安装PHP7.2版本的PThread.
前言:

之前想通过PHP多线程分批去处理请求,等最后安装好,运行成功后才发现官方的一句话,最后不得不放弃使用了。

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 ;)


安装:

1,我是使用oneinstack 集成工具,安装Thread前需要在oneinstack/options.conf 增加php编译扩展(开启安全模式)

php_modules_options='--enable-maintainer-zts ' 2,检查是否已开启安全线程 php -i | grep Thread => 看到enable 表示是安全版 3,下载最新的Pthreads扩展

git clone https://github.com/krakjoe/pthreads.git 4,在下载好的pthreads目录下执行phpsize命令 phpize 5,执行安装命令

./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
6,写入配置文件
echo "extension=pthreads.so" >> /usr/local/php/etc/php.ini 7,测试代码 class My extends Thread {
public function run() {
sleep(10);
echo("HELLO 1 \r\n");
}
}

class My2 extends Thread {
public function run() {
/* ... */
sleep(3);
echo("HELLO 2 \r\n");
}
}



class My3 extends Thread {
public function run() {
/* ... */
sleep(1);
echo("HELLO 3 \r\n");
}
}


class My4 extends Thread {
public function run() {
/* ... */
sleep(5);
echo("HELLO 4 \r\n");
}
}


$my_1 = new My();
$my_2 = new My2();
$my_3 = new My3();
$my_4 = new My4();

$my_1->start();
$my_2->start();
$my_3->start();
$my_4->start();

$my_1->join();
$my_2->join();
$my_3->join();
$my_4->join();
echo("main ");



ECHO
HELLO 3 => HELLO 2 => HELLO 4 => HELLO 1 => main
8,参考

http://blog.51cto.com/quietnight/1765370



我的博客:http://hihubs.com/article/286
收藏
273579540
积分:2313 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /