您好,欢迎访问一九零五行业门户网

php安装threads多线程扩张

php安装threads多线程扩展
php5.3或以上,且为线程安全版本。apache和php使用的编译器必须一致。
通过phpinfo()查看thread safety为enabled则为线程安全版。
通过phpinfo()查看compiler项可以知道使用的编译器。本人的为:msvc9 (visual c++ 2008)。
一、下载pthreads扩展
下载地址:http://windows.php.net/downloads/pecl/releases/pthreads
二、安装pthreads扩展
复制php_pthreads.dll 到目录 bin\php\ext\ 下面。
复制pthreadvc2.dll 到目录 bin\php\ 下面。
复制pthreadvc2.dll 到目录 c:\windows\system32 下面。
打开php配置文件php.ini。在后面加上extension=php_pthreads.dll
提示!windows系统需要将 pthreadvc2.dll 所在路径加入到 path 环境变量中。我的电脑--->鼠标右键--->属性--->高级--->环境变量--->系统变量--->找到名称为path的--->编辑--->在变量值最后面加上pthreadvc2.dll的完整路径(本人的为c:\windows\system32\pthreadvc2.dll)。
三、添加thread类
hooks[] = $func;
$this->args[] = $args;
return true;
}
function runthread()
{
if(isset($_get['flag']))
{
$flag = intval($_get['flag']);
}
if($flag || $flag === 0)
{
call_user_func_array($this->hooks[$flag], $this->args[$flag]);
}
else
{
for($i = 0, $size = count($this->hooks); $i {
$fp=fsockopen($_server['http_host'],$_server['server_port']);
if($fp)
{
$out = get {$_server['php_self']}?flag=$i http/1.1rn;
$out .= host: {$_server['http_host']}rn;
$out .= connection: closernrn;
fputs($fp,$out);
fclose($fp);
}
}
}
}
}

四、测试pthreads扩展
include('thread.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();

其它类似信息

推荐信息