PHP Installation Threads multithreaded expansion of the basic tutorial _php instance

Source: Internet
Author: User
Tags php class thread class

First, download pthreads extension

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

Second, to determine whether PHP is a TS or NTS version

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

Third, according to the 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 package, where 0.1.0 is represented as the current pthreads version number, 5.4 is the PHP version number, TS is before the PHP corresponding to the TS, NTS version, VS9 Representative is visual The Studio 2008 compiler compiler compiles, and the last x86 represents a 32-bit version.

Four, download pthreads extension

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

V. Installation of Pthreads expansion

Copy Php_pthreads.dll to the directory bin\php\ext\ below.
Copy PthreadVC2.dll to the directory bin\php\ below.
Copy PthreadVC2.dll to the directory C:\windows\system32 below.
Open the PHP configuration file php.ini. Plus Extension=php_pthreads.dll in the back.
Tips! The Windows system needs to add the path where the PthreadVC2.dll resides to the PATH environment variable. My Computer---> right mouse button---> Properties---> Advanced---> Environment variables---> System variables---> Find the name path---> Edit---> After the value of the variable plus the full path of the PthreadVC2.dll (my C:\WINDOWS\system32\pthreadVC2.dll).

Six, add thread class

 <?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[' 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 ($_se
        rver[' 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 expansion of the basic course, I hope you like.

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.