Windows下安装PHP多线程扩展

1、下载
windows版本的下载地址
http://windows.php.net/downloads/pecl/releases/pthreads/0.1.0/
https://windows.php.net/downloads/pecl/releases/pthreads/2.0.9/
选择合适的版本 根据php的ts\nts版本选择对应的pthreads版本
根据本人环境,我下载的是php_pthreads-0.1.0-5.5-ts-vc11-x86.zip。
0.1.0代表pthreads的版本。
5.5代表php的版本。
ts表示php要线程安全版本的。
vc11表示php要Visual C++ 2011编译器编译的。
x86则表示32位的

其中x86需要phpinfo()去查看。如果版本选错,后面Apache启动不起来

2、安装
2.1、将pthreadVC2.dll文件拷贝到php目录中
在这里插入图片描述
2.2、将php_pthreads.dll文件拷贝到php/ext目录中
在这里插入图片描述
2.3、打开php.ini文件添加 extension=php_pthreads.dll

在这里插入图片描述
2.4、打开apache httpd.conf文件添加 LoadFile “D:\phpStudy\PHPTutorial\php\php-5.5.38\pthreadVC2.dll”
在这里插入图片描述
如果添加了LoadFile后发现Apache启动不了,那么去检查自己的位数,看看下载的文件位数是否和自己系统相符合

3、重启Apache
打开phpinfo()
在这里插入图片描述
现在安装已完成

4、示例代码

<?Php
date_default_timezone_set('PRC');
/*error_reporting(E_ERROR | E_PARSE);*/

 
class test extends \Thread {
    public function __construct($arg){
        $this->arg = $arg;
    }
    public function run(){
        if($this->arg){
            sleep(3);
            printf("Hello %s\n", $this->arg);
        }
    }
}
$thread = new test("World");
 
if($thread->start())
  $thread->join();
 
echo "main thread\r\n";


?>

结果显示:
在这里插入图片描述
一切OK了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值