1 | <?php |
||
10 | class MessageQueue |
||
11 | { |
||
12 | use IpcKeyTrait; |
||
13 | |||
14 | /** |
||
15 | * The resource that can be used to access to the system v message queue |
||
16 | * @var resource |
||
17 | */ |
||
18 | protected $mqId; |
||
19 | |||
20 | /** |
||
21 | * The message type |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $messageType; |
||
25 | |||
26 | protected $unserialize = true; |
||
27 | |||
28 | public function __construct($messageType = 1, $pathname = __FILE__, $mode = 0666) |
||
34 | |||
35 | /** |
||
36 | * Sends the message to the queue |
||
37 | * @param string $message |
||
38 | * @param bool $blocking |
||
39 | * @return bool |
||
40 | */ |
||
41 | public function send($message, $blocking = true) |
||
56 | |||
57 | /** |
||
58 | * Gets the message from the queue |
||
59 | * @param bool $blocking |
||
60 | * @param int $maxSize The max size you want receive(Unit:bytes) |
||
61 | * @return string|false |
||
62 | */ |
||
63 | public function receive($blocking = true, $maxSize = 10240) |
||
81 | |||
82 | /** |
||
83 | * Sets information for the queue |
||
84 | * @param array $states |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function setStates(array $states) |
||
91 | |||
92 | /** |
||
93 | * Sets information for the queue by specifying the key and value |
||
94 | * @param string $key |
||
95 | * @param string|int $value |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function setState($key, $value) |
||
104 | |||
105 | /** |
||
106 | * Gets the information of the queue |
||
107 | * |
||
108 | * The return value is an array whose keys and values have the following meanings: |
||
109 | * Array structure for msg_stat_queue |
||
110 | * msg_perm.uid The uid of the owner of the queue. |
||
111 | * msg_perm.gid The gid of the owner of the queue. |
||
112 | * msg_perm.mode The file access mode of the queue. |
||
113 | * msg_stime The time that the last message was sent to the queue. |
||
114 | * msg_rtime The time that the last message was received from the queue. |
||
115 | * msg_ctime The time that the queue was last changed. |
||
116 | * msg_qnum The number of messages waiting to be read from the queue. |
||
117 | * msg_qbytes The maximum number of bytes allowed in one message queue. On Linux, this value may be read and modified via /proc/sys/kernel/msgmnb. |
||
118 | * msg_lspid The pid of the process that sent the last message to the queue. |
||
119 | * msg_lrpid The pid of the process that received the last message from the queue. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getState() |
||
127 | } |
||
128 |