PHP Installation Threads multithreaded Extensions Basic Tutorial _php instance

Source: Internet
Author: User
First, download pthreads extension

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

Second, to determine whether PHP is TS or NTS version

Through Phpinfo (); Look at the thread Safety item in it, this project is to see if it is thread safe, if yes: enabled, generally it should be TS version, otherwise it is version nts.

Third, according to PHP ts\nts version to select the corresponding pthreads version

I PHP version is 5.4.17, so download php_ Pthreads-0.1.0-5.4-ts-vc9-x86.zip file package, where 0.1.0 is represented as the current pthreads version number, 5.4 is the PHP version number, TS is previously judged PHP corresponding TS, NTS version, VS9 represents the visual The Studio compiler compiler compiles, and the last x86 represents a 32-bit version.

Iv. Download Pthreads Extension

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

V. Installation of pthreads extensions

Copy the Php_pthreads.dll to the directory bin\php\ext\ below.
Copy the PthreadVC2.dll to the directory bin\php\ below.
Copy the PthreadVC2.dll to the directory C:\windows\system32 below.
Open php config file php.ini. Add Extension=php_pthreads.dll to the back.
Tips! The Windows system needs to include the path of the PthreadVC2.dll into the PATH environment variable. My Computer---> Right---> Properties---> Advanced---> Environment variables---> System variables---> Find---> Edit---> Named path At the end of the variable value, add the full path to the PthreadVC2.dll (my C:\WINDOWS\system32\pthreadVC2.dll).

Vi. adding the 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 for you to introduce the PHP installation threads multithreaded extension Basic tutorial, I hope you like.

  • Related Article

    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.