Php multi-thread Q & A. How can this problem be solved?

Source: Internet
Author: User
Php multi-thread Q & a I have seen some demos on the internet. many of them are the same. I got a local test and encountered a problem: // a. php & nbsp; & lt ;? Phpfunction & nbsp; runThread () {& nbsp; $ fp & nbsp; = & nbsp; fsockopen ('localhost', & nbsp; 80, & n php multi-thread Q &
I saw some demos on the Internet, many of which were the same. I got the local test and encountered a problem:
// A. php
Function runThread (){
$ Fp = fsockopen ('localhost', 80, $ errno, $ errmsg );
Fputs ($ fp, "GET/a. php? Act = B ");
Fclose ($ fp );
}

Function (){
$ 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 ['AC']) $ _ GET ['AC'] = 'a ';

If ($ _ GET ['act '] = 'a '){
RunThread ();
A ();
}
Else if ($ _ GET ['AC'] = 'B') B ();
?>

Each time I access localhost/. in php, records can only be written to result_a.log, but will never be written to result_ B .log. I am sure that fsocket extension can be enabled in my php environment, could you give me some advice on multithreading php:
------ Solution --------------------
Because your default $ _ GET ['AC'] is to execute the () function.
Run localhost/a. php? Try act = B
------ Solution --------------------
It should be caused by missing headers of data packets in fputs.
My opinion:
1. use firebug to know what to write and observe the header of your request.
2. discard the fsock series functions. this is not supported in many places, but you can use curl to simulate your request.
------ Solution --------------------
Use firebug to check for errors, or use echo to check where the program is executed? The check fails.

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.