Analysis of the multi-thread in PHP
Author: handsome like scum Joined: 2004-02-24 Views:? 141 PHP Multiple Threads see this title, you must have thought I was crazy .. but in fact I really did below Yes. Some of my practices have been experimenting. I know. We know that PHP itself does not support multi-threaded, but our web server is supporting multi-threaded. That is to say, you can get more people together. This is also I am PHP implements multi-thread foundation. Suppose we run a.php file now. But I asked the web server in the program to run another B.php The two files will be executed simultaneously. (PS: one After the link request is sent, the web server will execute it, regardless of whether the client has already exited) Some time, we want to run another file, but a part of this document. What should I do? Actually by parameters To control a.php to run which program. Look at an example: //a.php
PHP code:
Function Runthread ()
{
$ fp = fsockopen ('LocalHost', 80, $ Errno, $ Errmsg);
FPUTS ($ fp, "get /a.php?Act=b/r/n/r/n"); // The second parameter here is the request head specified in the HTTP protocol
// Do not understand, please see the definition in RFC
Fclose ($ fp);
}
Function a ()
{
$ fp = fopen ('result_a.log', 'w');
FPUTS ($ FP, 'SET IN'. DATE ('H: I: S', Time ()). (Double) Microtime (). "/ r / n");
Fclose ($ fp);
}
Function B ()
{
$ fp = fopen ('result_b.log', 'w');
FPUTS ($ FP, 'SET IN'. DATE ('H: I: S', Time ()). (Double) Microtime (). "/ r / n");
Fclose ($ fp);
}
IF (! isset ($ _ get ['Act']) $ _GET ['ACT'] = 'A';
IF ($ _ get ['ACT'] == 'a')
{
Runthread ();
a ();
}
ELSE IF ($ _ get ['ACT'] == 'b') b ();
?>