Description

msg_send() sends a message of type
msgtype (which MUST be greater than 0) to
the message queue specified by queue.

Parameters

queue

msgtype

message

serialize

The optional serialize controls how the
message is sent. serialize
defaults to TRUE which means that the message is
serialized using the same mechanism as the session module before being
sent to the queue. This allows complex arrays and objects to be sent to
other PHP scripts, or if you are using the WDDX serializer, to any WDDX
compatible client.

blocking

If the message is too large to fit in the queue, your script will wait
until another process reads messages from the queue and frees enough
space for your message to be sent.
This is called blocking; you can prevent blocking by setting the
optional blocking parameter to FALSE, in which
case msg_send() will immediately return FALSE if the
message is too big for the queue, and set the optional
errorcode to MSG_EAGAIN,
indicating that you should try to send your message again a little
later on.

errorcode

Return Values

Returns TRUE on success or FALSE on failure.

Upon successful completion the message queue data structure is updated as
follows: msg_lspid is set to the process-ID of the
calling process, msg_qnum is incremented by 1 and
msg_stime is set to the current time.

User Contributed Notes 6 notes

I created example how to comunnicate with programe written in C throught messages queues. First run C program (it will create queue) then PHP script.

C code compile with: gcc -std=c99 -o test_queue test_queue.c

test_queue.c:/*** Example how to use System V Messages Queues with PHP and C program.* This is simple server which create message queue and receive message from it.* Based on Beej's Guide to Unix IPC* Autor: Jan Drazil, <qeekin at gmail dot com>*/

test_queue.php:<?php/*** Example how to use System V Messages Queues with PHP and C program.* This is simple server which create message queue and receive message from it.* Based on Beej's Guide to Unix IPC* Autor: Jan Drazil, <qeekin at gmail dot com>*/

When sending non-complex (serialize = false) messages to a program in C, you need to add the null character to the string (\0). Otherwise the previous message will be partially visible if it is longer than the current message. Took some kind help from comp.lang.php for me to figure that out. While it seems so obvious now, I thought I'd share it here.

I think it is kinda lame why I cannot find out (easily) explicitly which types of messages are allowed and which ones are not. Maybe we can start our own little list. I know that strings work, and arrays do not.