1. 程式人生 > >PHP安裝pthreads多執行緒擴充套件教程[windows篇]

PHP安裝pthreads多執行緒擴充套件教程[windows篇]

一、判斷PHP是ts還是nts版

通過phpinfo(); 檢視其中的 Thread Safety 項,這個專案就是檢視是否是執行緒安全,如果是:enabled,一般來說應該是ts版,否則是nts版。

二、根據PHP ts\nts版選擇對應pthreads的版本

本人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位的版本。

三、安裝pthreads擴充套件

將下載好的php_pthreads-0.1.0-5.4-ts-vc9-x86.zip檔案包解壓得到 pthreadVC2.dll和php_pthreads.dll檔案,把vc2檔案放到php.exe同級目錄,把php_pthreads.dll放到擴充套件目錄下。 1、修改php.ini檔案 新增extension=php_pthreads.dll
2、修改Apache配置檔案httpd.conf 新增LoadFile "X:/PHP5/pthreadVC2.dll"
3、重啟Apache伺服器

四、測試pthreads擴充套件

<?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();
?>
執行以上程式碼得到“HelloWorld”,就說明安裝pthreads擴充套件成功!