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了