Example of php multi-thread pipeline communication

Source: Internet
Author: User
Example of php multi-thread pipeline communication
This article introduces the example of multi-threaded pipeline communication in php. For more information, see.

The code for multi-threaded php pipe communication is as follows:

     Export OPath = $ export OPath;} // write the pipeline function to start function open_write () {$ this-> w_pipe = fopen ($ this-> export OPath, 'w '); if ($ this-> w_pipe = NULL) {error ("open pipe {$ this-> export OPath} for write error. "); return false;} return true;} function write ($ data) {return fwrite ($ this-> w_pipe, $ data);} function write_all ($ data) {$ w_pipe = fopen ($ this-> export OPath, 'w'); fwrite ($ w_pipe, $ data); fclose ($ w_pipe);} function Close_write () {return fclose ($ this-> w_pipe);} // read pipeline related function start function open_read () {$ this-> r_pipe = fopen ($ this-> export OPath, 'r'); if ($ this-> r_pipe = NULL) {error ("open pipe {$ this-> OPath} for read error. "); return false;} return true;} function read ($ byte = 1024) {return fread ($ this-> r_pipe, $ byte);} function read_all () {$ r_pipe = fopen ($ this-> export OPath, 'r'); $ data = ''; while (! Feof ($ r_pipe) {// echo "read one K \ n"; $ data. = fread ($ r_pipe, 1024);} fclose ($ r_pipe); return $ data;} function close_read () {return fclose ($ this-> r_pipe );} /*** delete the MPs queue ** @ return boolean is success */function rm_pipe () {return unlink ($ this-> export OPath );}} /* This class implements simple pipeline communication */?>

For the implementation of multithreading in php, refer to the following article: Understanding the advantages of multithreading in php. use php multi-threaded to capture web pages. share php multi-threaded code (without using fork) examples: php multi-threaded code sharing examples of php multi-threaded download

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.