PHP multi-threaded troubleshooting, how to deal with

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