PHP下操作Linux消息队列完成进程间通信的方法
关于Linux系统进程通信的概念及实现可查看:http://www.ibm.com/developerworks/cn/linux/l-ipc/
关于Linux系统消息队列的概念及实现可查看:http://www.ibm.com/developerworks/cn/linux/l-ipc/part4/
PHP的sysvmsg模块是对Linux系统支持的System V IPC中的System V消息队列函数族的封装。我们需要利用sysvmsg模块提供的函数来进进程间通信。先来看一段示例代码_1:
<div class="codetitle"><a style="CURSOR: pointer" data="54981" class="copybut" id="copybut54981" onclick="doCopy('code54981')"> 代码如下:
<div class="codebody" id="code54981">
<?
PHP $message_queue_key = ftok(
FILE,'a');
$message_queue = msg_get_queue($message_queue_key,0666);
var_dump($message_queue);
$message_queue_status = msg_stat_queue($message_queue);
print_r($message_queue_status);
//向消息队列中写
msg_send($message_queue,1,"Hello,World!");
$message_queue_status = msg_stat_queue($message_queue);
print_r($message_queue_status);
//从消息队列中读
msg_receive($message_queue,$message_type,1024,$message,true,MSG
IPCNowAIT);
print_r($message."\r\n");
msg_remove_queue($message_queue);
?>