《PHP應用:PHP安裝threads多線程擴展基礎教程》要點:
本文介紹了PHP應用:PHP安裝threads多線程擴展基礎教程,希望對您有用。如果有疑問,可以聯系我們。
PHP學習一、下載pthreads擴展
PHP學習下載地址:http://windows.php.net/downloads/pecl/releases/pthreads
PHP學習二、判斷PHP是ts還是nts版
PHP學習通過phpinfo(); 查看其中的 Thread Safety 項,這個項目就是查看是否是線程平安,如果是:enabled,一般來說應該是ts版,否則是nts版.
PHP學習三、根據PHP ts\nts版選擇對應pthreads的版本
PHP學習本人php版本是5.4.17的所以下載php_pthreads-0.1.0-5.4-ts-vc9-x86.zip文件包,其中0.1.0表示為當前pthreads版本號,5.4為php版本號,ts便是之前判斷php對應的ts、nts版,vs9代表是Visual Studio 2008 compiler編譯器編譯的,最后的x86代表的是32位的版本.
PHP學習四、下載pthreads擴展
PHP學習下載地址:http://windows.php.net/downloads/pecl/releases/pthreads
PHP學習五、安裝pthreads擴展
PHP學習復制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).
PHP學習六、添加thread類
PHP學習
<?php
class Thread
{
var $hooks = array();
var $args = array();
function thread()
{
}
function addthread($func)
{
$args = array_slice(func_get_args(), 1);
$this->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 < $size; $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);
}
}
}
}
}
PHP學習七、測試pthreads擴展
PHP學習
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();
PHP學習以上內容給年夜家介紹了PHP安裝threads多線程擴展基礎教程,希望年夜家喜歡.
歡迎參與《PHP應用:PHP安裝threads多線程擴展基礎教程》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/8387.html