Home  >  Article  >  Backend Development  >  Wampserver installation pthreads multi-thread extension tutorial

Wampserver installation pthreads multi-thread extension tutorial

WBOY
WBOYOriginal
2016-07-29 09:16:131522browse
Multi-threading is needed in the project. I found that PHP can support multi-threading after installing pthreads, so I googled it. The approximate installation content is as follows.

based on PHP For the tsnts version, choose the version corresponding to pthreads

Download pthreads : http://windows.php.net/downloads/pecl/releases/pthreads/2.0.9/


My 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 represents the current pthreads version number, 5.4 is the php version number (this requires special attention, I have failed many times and it is broken here) , ts is the previous judgment of php The corresponding ts and nts versions, vs9 represents Visual It is compiled with the Studio 2008 compiler, and the last x86 represents the 32-bit version (64-bit systems can also be used, because there is no 64-bit version at all).

Install the pthreads extension

After the file is downloaded, only 2 files are needed: pthreadVC2.dll and php_pthreads.dll ;
1. Modify the php.ini file Add extension=php_pthreads.dll (It needs to be noted here that php.ini has a copy under apache and php, it is recommended to add it)
2. Put the pthreadVC2.dll file into the same directory as php.exe, and put the php_pthreads.dll into the extension directory.
In addition, copy a copy of pthreadVC2.dll and put it in the apache/bin directory.
3. Restart wampserver.

Test the pthreads extension

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


Run the above code and get "HelloWorld", which means the pthreads extension is successfully installed. !

The above introduces the wampserver installation pthreads multi-thread extension tutorial, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn