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 |