PHP installation of threads multi-thread extension basic tutorial, threads multithreading _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP installation of threads multi-thread extension basic tutorial, threads multi-thread. PHP installation of threads multi-thread extension basic tutorial, threads multithreading I. download pthreads extension: windows. php. netdownloadspeclreleasespthreads II. determine that PHP is t PHP installation of threads multi-thread extension basic tutorial, threads multithreading

1. download the pthreads extension

: Http://windows.php.net/downloads/pecl/releases/pthreads

II. determine whether PHP is a ts or an ETS version.

Use phpinfo (); to check the Thread Safety item. this project is to check whether it is Thread security. if it is: enabled, it should be ts version; otherwise, it will be the ETS version.

3. select the corresponding pthreads version based on PHP ts \ NT

The idea file package, where 0.1.0 indicates the current pthreads version number, 5.4 indicates the php version number, ts indicates the ts version corresponding to php, and vs9 indicates that it is compiled by the Visual Studio 2008 compiler, the last x86 version represents a 32-bit version.

4. download the pthreads extension

: Http://windows.php.net/downloads/pecl/releases/pthreads

5. install pthreads extension

Copy php_pthreads.dll to the directory bin \ php \ ext.
Copy pthreadVC2.dll to the directory bin \ php.
Copy pthreadVC2.dll to the directory C: \ windows \ system32.
Open the php configuration file php. ini. Add extension = php_pthreads.dll
Prompt! In Windows, you must add the PATH of pthreadVC2.dll to the PATH environment variable. My computer ---> right-click ---> properties ---> advanced ---> environment variables ---> System variables ---> find the Path named ---> edit ---> add pthreadVC2.dll to the end of the variable value complete path (my C: \ WINDOWS \ system32 \ pthreadVC2.dll ).

6. add thread class

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

VII. test pthreads extension

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();

The above content introduces you to the basic tutorial of installing threads multi-thread extension in PHP. I hope you will like it.

Example 1, download pthreads extension: http://windows.php.net/downloads/pecl/releases/pthreads 2, Judge PHP is t...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.