擴展使用要求:php5.3或以上,且爲線程安全版本php
下載pthreads擴展包是注意編譯器版本,phpinfo()裏面的Compiler項apache
pthreads擴展下載:http://windows.php.net/downloads/pecl/releases/pthreads/windows
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\ 下面this
複製pthreadVC2.dll 到目錄apache\bin\ 下面.net
打開php配置文件php.ini。在後面加上extension=php_pthreads.dll線程
2.重啓apacheblog
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模式下運行