msg_get_queue

(PHP 4 >= 4.3.0, PHP 5)

msg_get_queue — Create or attach to a message queue

Description

resourcemsg_get_queue
( int$key
[, int$perms = 0666
] )

msg_get_queue() returns an id that can be used to
access the System V message queue with the given
key. The first call creates the message queue with
the optional perms.
A second call to msg_get_queue() for the same
key will return a different message queue
identifier, but both identifiers access the same underlying message
queue.

Parameters

key

Message queue numeric ID

perms

Queue permissions. Default to 0666. If the message queue already
exists, the perms will be ignored.

Return Values

Returns a resource handle that can be used to access the System V message queue.

User Contributed Notes 6 notes

Warning: msg_get_queue() [function.msg-get-queue]: failed for key 0x12345678: No space left on device in /path/to/script.php on line 1

you may use the command "ipcrm" as root to clear the message queue. Use "man ipcrm" to get more info on it.The default setting for maximum messages in the queue is stored in /proc/sys/fs/mqueue/msg_max. To increase it to a maximum of 100 messages, just run:echo 100 > /proc/sys/fs/mqueue/msg_max

Please ensure to follow a good programming style and close/free all your message queues before your script exits to avoid those warning messages.

Lack of IPC_EXCL makes me unhappy. Of course, you can use ftok() to generate a unique key. This code is not allmighty, another process under the same user can open the queue and function returns true. But in some situation it could help.

// place two messages on the queue if (!msg_send ($key_t, 1, 'This is message #1', true, true, $msg_err)) echo "Msg not sent because $msg_err\n"; if (!msg_send ($key_t, 1, 'This is message #2 ', true, true, $msg_err)) echo "Msg not sent because $msg_err\n";

// lets look at the queue structure 'msg_qnum' is really what we want to see // it should be '2' print_r(msg_stat_queue($key_t));