PHP IPC函数介绍---消息队列

本文详细介绍了消息队列的基本操作,包括创建、检测、发送、接收、统计和销毁队列的过程,并通过实例展示了PHP实现消息队列操作的具体步骤。

msg_get_queue — Create or attach to a message queue
msg_queue_exists — Check whether a message queue exists
msg_receive — Receive a message from a message queue
msg_remove_queue — Destroy a message queue
msg_send — Send a message to a message queue
msg_set_queue — Set information in the message queue data structure
msg_stat_queue — Returns information from the message queue data structure

#!/usr/bin/env php
<?php
$queue_id=10086; //定义一个队列id
if(!msg_queue_exists($queue_id)){ //检测队列id是否存在,即被使用
        $queue=msg_get_queue($queue_id);
}
//向消息队列发送消息
msg_send($queue,1,serialize(array('a'=>'hello world','name'=>'测试')));
//展示消息队列的统计信息
$queue_info=msg_stat_queue($queue);
print_r($queue_info);
//从消息队列中接收消息,消息是以引用的方式获取
msg_receive($queue,0,$msg_typei,1024,$msg,true,null,$error);
print_r(unserialize($msg));
msg_remove_queue($queue); //销毁消息队列

转载于:https://www.cnblogs.com/xiazh/archive/2012/11/23/2783047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值