Php installs threads multi-threaded extension 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 ThreadSafety is enabled, which is the thread Security Edition. You can use phpinfo () to view the Compiler. My name is MSVC9 (VisualC ++ 2008 ). & Nbsp; 1. download pthread php to install threads multi-thread extension
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 named ---> edit ---> add pthreadVC2.dll to the end of the variable value complete path (my 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();