Php multi-thread Q & A multi-thread php
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'm sure I can enable fsocket extension in my php environment.
Reply to discussion (solution)
Turn it on, give me some advice.
Because your default $ _ GET ['AC'] is to execute the () function.
Run localhost/a. php? Try act = B
Php multithreading?
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.
Use firebug to check for errors, or use echo to check where the program is executed? The check fails.
Okay, it's time to close the post.