: This article describes how to install threads multi-thread extension in php. if you are interested in the PHP Tutorial, refer to it. Php5.3 or later, and is a thread-safe version. The compiler used by apache and php must be consistent.
Use phpinfo () to check that if Thread Safety is enabled, it is the Thread Security Edition.
You can use phpinfo () to view the Compiler. My name is MSVC9 (Visual C ++ 2008 ).
1. download the pthreads extension
: Http://windows.php.net/downloads/pecl/releases/pthreads
II. 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 ---> edit ---> add the complete Path of pthreadVC2.dll to the end of the variable value (C: \ WINDOWS \ system32 \ pthreadVC2.dll ).
3. add thread class
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($_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);
}
}
}
}
}
IV. 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 describes how to install threads multi-thread extension in php, including my computer content. I hope my friends who are interested in PHP tutorials will help me.