扩展使用要求:php5.3或以上,且为线程安全版本
下载pthreads扩展包是注意编译器版本,phpinfo()里面的Compiler项
pthreads扩展下载:http://windows.php.net/downloads/pecl/releases/pthreads/
pthreads函数文档:http://www.php.net/manual/zh/book.pthreads.php
1.下载pthreads扩展包,获取里面的php_pthreads.dll和pthreadVC2.dll
复制php_pthreads.dll 到目录 phpext 下面
复制pthreadVC2.dll 到目录php 下面
复制pthreadVC2.dll 到目录apachein 下面
打开php配置文件php.ini。在后面加上extension=php_pthreads.dll
2.重启apache
3.测试扩展是否打开
<?php class AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s ", $this->arg); } } } $thread = new AsyncOperation("World"); if($thread->start()) $thread->join(); ?>
运行以上代码出现 Hello World,说明pthreads扩展安装成功!
注意只能在cli模式下运行