This article mainly introduces the usage of the PHP message queue and analyzes the related skills of the PHP message queue for inter-process communication in Linux based on the instance form, for more information about how to use a PHP message queue, see the following example. We will share this with you for your reference. The details are as follows:
This message queue is used for process communication in linux.
# Create an id $ key = ftok (_ DIR __, 'r') based on the path and suffix; # obtain the message $ q = msg_get_queue ($ key) in the queue ); # Delete the queue msg_remove_queue ($ q); # obtain the queue status information $ status = msg_stat_queue ($ q); print_r ($ status); echo "\ n "; for ($ I = 0; $ I <100; $ I ++) {/*** add a message to the queue * resource $ queue, int $ msgtype, mixed $ message [, bool $ serialize = true [, bool $ blocking = true [, int & $ errorcode] * $ msgtype: message Type * $ message: specific Data * $ serialize: whether to serialize * $ blocking: whether to block. when the queue is full, blocking is performed, if this parameter is set to non-blocking, an error message MSG_EAGAIN will be generated */$ flag = msg_send ($ q, 111, array ('a' => 1), true, false, $ errorcode ); var_dump ($ errorcode);}/** receives the message resource $ queue, int $ desiredmsgtype, int & $ msgtype, int $ maxsize, mixed & $ message [, bool $ unserialize = true [, int $ flags = 0 [, int & $ errorcode] $ desiredmsgtype: 0 indicates that data is returned from the beginning of the queue, bigger 0: A specific queue $ maxsize: the maximum value of data. if this value is obtained for a message, an error occurs. $ msgtype: the specific type of the message, because $ desiredmsgtype can be of no type specified, this parameter is set to 0 $ flags: MSG_IPC_NOWAIT. if the queue is empty, it will be returned directly (not blocked). for details about msg_0000t MSG_NOERROR, see the manual */$ data = msg_receive ($ q, 0, $ type, 200, $ msg); var_dump ($ data); echo "\ n"; var_dump ($ type); echo "\ n"; var_dump ($ msg); echo "\ n ";
Queue status information: Reference Manual
Array([msg_perm.uid] => 1015[msg_perm.gid] => 100[msg_perm.mode] => 438[msg_stime] => 0[msg_rtime] => 0[msg_ctime] => 1411830331[msg_qnum] => 0[msg_qbytes] => 65536[msg_lspid] => 0[msg_lrpid] => 0)
In linux, run the ipc command to view and use the ipcrm command to delete the file.