PHP安裝threads多線程擴充基礎教程_php執行個體

來源:互聯網
上載者:User

一、下載pthreads擴充

下載地址:http://windows.php.net/downloads/pecl/releases/pthreads

二、判斷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擴充

下載地址: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類

<?phpclass 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);        }      }    }  }}

七、測試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();

以上內容給大家介紹了PHP安裝threads多線程擴充基礎教程,希望大家喜歡。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.