【问题标题】:Why is the PHP ipc message not in the queue?为什么 PHP ipc 消息不在队列中?
【发布时间】:2013-10-03 18:59:34
【问题描述】:

在 PHP 中,我尝试通过 IPC 发送消息,并立即检查消息是否在队列中。这是一个测试代码:

$rQueue = msg_get_queue(12345, 0660);
msg_send($rQueue, 0, "test", FALSE, FALSE);
print_r(msg_stat_queue($rQueue));

从给定队列中打印出统计信息,指示msg_qnum=0,即队列中没有消息。预期的行为是在队列中看到至少一条消息。问题出在哪里?

【问题讨论】:

    标签: php ipc


    【解决方案1】:

    查看manual 它说:

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

    msg_send() 发送 msgtype 类型的消息(必须大于 0) 到queue指定的消息队列。

    所以将第二个参数从 0 改为 1 即可解决问题。

    还请查看error_reporting() 函数。当我运行你的代码时,PHP 用警告表示问题:

    PHP 警告:msg_send(): msgsnd failed: Invalid argument

    【讨论】:

      猜你喜欢
      • 2012-09-19
      • 2021-03-12
      • 2020-10-30
      • 1970-01-01
      • 2013-01-05
      • 2021-06-24
      • 2019-04-23
      • 2010-12-06
      • 2013-04-16
      相关资源
      最近更新 更多