PHP Message Queue usage instance analysis, php queue instance analysis
This example describes the usage of the PHP message queue. 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.