Php installation of threads multi-thread expansion

Source: Internet
Author: User
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();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.