网上有教程,说的都不是太对,哎。
原文地址:
https://www.cnblogs.com/kobigood/p/5667720.html
下载pthreads 文件 http://windows.php.net/downloads/pecl/releases/pthreads/3.1.5/
2.把 pthreadVC2.dll 放到 php.exe文件同目录,还有copy到system32下面
3.把php_pthreads.dll放到扩展目录下。
但是他有个地方写错了,不是保存成php-cli.php,而是保存成php-cli.ini,我下的3.1.6,php环境是7.0.5
并且文件中要写:
extension_dir = "E:\webhome\php7.0.5\ext"
;多线程
extension=php_pthreads.dll
安装完成后,不是直接通过页面执行的PHP,而是通过命令提示符里 执行的
最后附上别人的测试代码:
<?php
class AsyncOperation extends Thread {
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
printf("Hello %s\n", $this->arg);
echo 'daa';
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();