Php multi-thread Q &

Source: Internet
Author: User
Tags php multithreading
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.

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.