搜尋
首頁php教程PHP开发PHP安裝threads多執行緒擴充基礎教學

一、下載pthreads擴充

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

二、判斷PHP是ts還是nts版

透過其中的Thread(); 查看其中的Thread Safety 項,這個項目就是要查看是否是執行緒安全,如果是:enabled,一般來說應該是ts版,否則是nts版。

三、根據PHP tsnts版選擇對應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.phpdext 到目錄下目錄 到目錄
複製php_pthreads。
複製pthreadVC2.dll 到目錄 binphp 下面。
複製pthreadVC2.dll 到目錄 C:windowssystem32 下面。
開啟php設定檔php.ini。在後面加上extension=php_pthreads.dll

提示! Windows系統需要將 pthreadVC2.dll 所在路徑加入 PATH 環境變數。我的電腦--->滑鼠右鍵--->屬性--->進階--->環境變數--->系統變數--->找到名稱為Path的--->編輯--->在變數值最後面加上pthreadVC2.dll的完整路徑(本人的為C:WINDOWSsystem32pthreadVC2.dll)。

六、新增thread類別

<?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[&#39;flag&#39;]))
    {
      $flag = intval($_GET[&#39;flag&#39;]);
    }
    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[&#39;HTTP_HOST&#39;],$_SERVER[&#39;SERVER_PORT&#39;]);
        if($fp)
        {
          $out = "GET {$_SERVER[&#39;PHP_SELF&#39;]}?flag=$i HTTP/1.1rn";
          $out .= "Host: {$_SERVER[&#39;HTTP_HOST&#39;]}rn";
          $out .= "Connection: Closernrn";
          fputs($fp,$out);
          fclose($fp);
        }
      }
    }
  }
}

   


七、測試pthreadsreads

include(&#39;thread.php&#39;);
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();

以上內容給大家介紹了PHPthreads 擴充功能基礎教學,希望以上內容可以讓大家介紹多點擴充功能基礎。

更多PHP安裝threads多執行緒擴充基礎教學相關文章請關注PHP中文網!


🎜
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器