Class Pipe { Public $ export OPath; Private $ w_pipe; Private $ r_pipe; /** * Automatically create an MPs queue. * * @ Param string $ name the name of the MPs queue * @ Param int $ mode: the permission of the media transcoding queue. by default, any user group can read and write data. */ Function _ construct ($ name = 'pipele', $ mode = 0666) { $ Export OPath = "/tmp/$ name.". posix_getpid (); If (! File_exists ($ paiopath )){ If (! Posix_mkfifo ($ export OPath, $ mode )){ Error ("create new pipe ($ name) error ."); Return false; } } Else { Error ("pipe ($ name) has exit ."); Return false; } $ This-> export OPath = $ export OPath; } //////////////////////////////////////// /////////// // Pipeline function writing starts //////////////////////////////////////// /////////// Function open_write () { $ This-> w_pipe = fopen ($ this-> export OPath, 'w '); If ($ this-> w_pipe = NULL ){ Error ("open pipe {$ this-> javasopath} 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 ); } //////////////////////////////////////// ///////////////// /// Start of the read pipeline function //////////////////////////////////////// //////////////// 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 ($ bytes = 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 ); } /** * Deleting an MPs queue * * @ Return boolean is success */ Function rm_pipe () { Return unlink ($ this-> javasopath ); } } ?> /* With this class, you can implement simple pipeline communication. */ |