php5.3 or more, and is a thread-safe version. The compilers used by Apache and PHP must be consistent.
Thread-safe version is phpinfo () to view thread safety as enabled.
You can see the compiler that is used by phpinfo () to view the compiler item. my: MSVC9 (Visual C + + 2008).
First, download pthreads extension
Download Address: Http://windows.php.net/downloads/pecl/releases/pthreads
Second, install pthreads extension
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).
Third, add the 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 the PHP installation threads multi-threaded extension, including my computer content, I hope that the PHP tutorial interested in a friend helpful.