1. Download the pthreads extension
Download address: http://windows.php.net/downloads/pecl/releases/pthreads
2. Determine whether PHP is a ts or nts version
View the Thread through phpinfo(); Safety item, this item is to check whether it is thread safe. If it is: enabled, generally speaking it should be the ts version, otherwise it should be the nts version.
3. Select the corresponding pthreads version according to the PHP tsnts version
My php version is 5.4.17, so download the php_pthreads-0.1.0-5.4-ts-vc9-x86.zip file package, where 0.1.0 represents the current pthreads version number, 5.4 is the PHP version number, ts is the ts and nts versions that were previously judged to correspond to PHP, vs9 represents the version compiled by the Visual Studio 2008 compiler, and the last x86 represents the 32-bit version.
4. Download the pthreads extension
Download address: http://windows.php.net/downloads/pecl/releases/pthreads
5. Install the pthreads extension
Copy php_pthreads.dll to the directory binphpext.
Copy pthreadVC2.dll to the directory binphp.
Copy pthreadVC2.dll to the directory C:windowssystem32.
Open the php configuration file php.ini. Add extension=php_pthreads.dll at the end
tip! Windows systems need to add the path of pthreadVC2.dll to the PATH environment variable. My Computer--->right mouse button--->Properties--->Advanced--->Environment Variables--->System Variables--->Find the path named Path---> ;Edit--->Add the full path of pthreadVC2.dll at the end of the variable value (mine is C:WINDOWSsystem32pthreadVC2.dll).
6. Add thread class
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); } } } } }
7. 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 like it.
For more articles related to PHP installation threads multi-thread extension basic tutorial, please pay attention to PHP Chinese website!