您的位置:首页 > 编程语言 > PHP开发

PHP之路——pthreads扩展

2017-03-09 10:48 211 查看
扩展使用要求: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 到目录 php\ext\ 下面

  复制pthreadVC2.dll 到目录php\ 下面

  复制pthreadVC2.dll 到目录apache\bin\ 下面

  打开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\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();
?>


  运行以上代码出现 Hello World,说明pthreads扩展安装成功!

注意只能在cli模式下运行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: