downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

msg_set_queue> <msg_remove_queue
[edit] Last updated: Fri, 17 May 2013

view this page in

msg_send

(PHP 4 >= 4.3.0, PHP 5)

msg_sendメッセージキューにメッセージを送信する

説明

bool msg_send ( resource $queue , int $msgtype , mixed $message [, bool $serialize = true [, bool $blocking = true [, int &$errorcode ]]] )

msg_send() は、queue で指定したメッセージキューに対して msgtype で指定した型 (0 より大きい数値である必要があります) のメッセージ message を送信します。

パラメータ

queue

msgtype

message

serialize

オプションのパラメータ serialize は、 message を送信する方法を制御します。 serialize のデフォルト値は TRUE で、 この場合 message が送信される前に セッションモジュールと同じ方法でシリアライズされます。 これにより、配列やオブジェクトのような複雑な形式のデータを 他の PHP スクリプトに送信することが可能となります。 また、もし WDDX シリアライザを使用しているなら、あらゆる WDDX 互換クライアントに対して同じことが可能となります。

blocking

メッセージがキューに収まらないほど大きい場合は、他のプロセスが 現在キューにあるメッセージを読み込んでキューの空き容量が確保されるまで スクリプトの実行を待ち続けます。これをブロックモードといいます。 オプションのパラメータ blockingFALSE に設定することでブロックモードではなくすることが可能で、 この場合、もしキューの空き容量よりも大きなメッセージを送信すると msg_send() はすぐに FALSE を返します。 また、オプションのパラメータ errorcodeMSG_EAGAIN に設定すると、 少し時間をおいてメッセージを再度送信しなければならないことが戻り値からわかります。

errorcode

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

処理が正常に完了すると、メッセージキューデータ構造体は以下のように更新されます。 msg_lspid には呼び出し元のプロセス ID が 設定され、msg_qnum が 1 増加し、 msg_stime が現在の時刻に設定されます。

参考



msg_set_queue> <msg_remove_queue
[edit] Last updated: Fri, 17 May 2013
 
add a note add a note User Contributed Notes msg_send - [5 notes]
up
1
Muffinman
6 months ago
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.
up
0
michael dot NO dot SP dot AM dot cordover+php at gmail dot com
3 years ago
After about an hour of debugging I've discovered the meaning of the undocumented "PHP Warning: msg_send(): msgsnd failed: Invalid argument" ($errorcode = 13).

This occurred when the size of $message was larger than msg_qbytes (see msg_stat_queue() for how to determine and change msg_qbytes).
up
0
shepik at yandex dot ru
3 years ago
$msgtype used in msg_send function can be any positive integer.
up
0
bryan-boone at msn dot com
5 years ago
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.
up
0
webmaster at toolshed51 dot com
10 years ago
Sample sending webpage, see msg_receive for matching service

<?php
    $MSGKEY
= 519051;

   
$msg_id = msg_get_queue ($MSGKEY, 0600);

    if (!
msg_send ($msg_id, 1, 'Hi', true, true, $msg_err))
        echo
"Msg not sent because $msg_err\n";
?>

 
show source | credits | sitemap | contact | advertising | mirror sites