Analyze the multi-thread in PHP ~

xiaoxiao2021-03-06  117

Analyze the multi-thread in PHP ~

Multi-thread in PHP? See this title, you must think that I am crazy .. But in fact I really do this. Below is some of my practices, it is really. We know that PHP itself is not Support multithreaded, but our web server is supported by multi-threaded. That is to say, many people can be accessed together. This is also the basis for the multi-thread in PHP. Suppose we are running now is a.php this file. But I asked the web server in the program to run another B.php. Then the two files will be executed at the same time. (PS: After a link request is sent, the web server will execute it, regardless of whether the client has exited Sometimes, we want to run another file, but a part of this document. What should I do? In fact, 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 ();

?>

转载请注明原文地址:https://www.9cbs.com/read-126637.html

New Post(0)