为什么 PHP ipc 消息不在队列中


Why is the PHP ipc message not in the queue?

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

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

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

查看手册,它说:

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

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

因此,将第二个参数从 0 更改为 1 可以解决问题。

也请看一下 error_reporting() 函数。当我运行您的代码时,PHP 通过警告指示问题:

PHP 警告: msg_send(): msgsnd 失败: 参数无效