Troubleshooting PHP Multithreading
On the Internet to see some of the demo, a lot of the same, their own to get the test, a bit of a problem:
a.php
function Runthread () {
$fp = Fsockopen (' localhost ', $errno, $errmsg);
Fputs ($fp, "get/a.php?act=b");
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 ();
?>
Every time I visit localhost/a.php, I can only write records in Result_a.log, Result_b.log never write a record, I'm sure my PHP environment can already enable fsocket extension, ask the master to point out Multithreading PHP
Share to:
------Solution--------------------
Because your default $_get[' act ' is to execute the A () function
Perform localhost/a.php?act=b test
------Solution--------------------
Should be the fputs inside of the packet head some less what caused.
My opinion:
1 Use Firebug to see what should be written, observe the Baotou you requested
2 Discard the Fsock series functions, which are not supported in many places, but you can use curl to simulate your request.
------Solution--------------------
Use Firebug to see the error, or where to go with the echo checker? Did not perform a step-by-step inspection.