PHP Installation Threads multithreaded Extensions

Source: Internet
Author: User
Tags phpinfo
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.

  • 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.