PHP Message Queue Usage Example Analysis _php skills

Source: Internet
Author: User

This example describes the use of PHP Message Queuing. Share to everyone for your reference, specific as follows:

This message queue is used for Linux, process communication

#根据路径和后缀创建一个id $key = Ftok (__dir__, ' R ');
#获取队列中的消息 $q = Msg_get_queue ($key);
#删除队列 Msg_remove_queue ($q);
#获取队列的状态信息 $status = Msg_stat_queue ($q);
Print_r ($status);
echo "\ n"; For ($i =0 $i <100; $i + +) {/** * Add message to queue * Resource $queue, int $msgtype, mixed $message [, bool $serialize = 
   True [, bool $blocking = true [, int & $errorcode]]] * $msgtype: Message type * $message: Specific data * $serialize: whether to serialize * $blocking: Blocking, when the queue is full, blocking, set to non-blocking will produce a msg_eagain error message * * $flag = Msg_send ($q, A., Array (' A ' =>1), True
  , false, $errorcode);
Var_dump ($errorcode); /** Receive Message resource $queue, int $desiredmsgtype, int & $msgtype, int $maxsize, mixed & $message [, BOOL $unseria Lize = true [, int $flags = 0 [, int & $errorcode]]] $desiredmsgtype: 0 means to return data from the front of the queue, bigger 0: a specific queue $maxsize: Data maximum , gets the message if "This value is an error $msgtype: The specific type of the message, because $desiredmsgtype can not specify the type, that is, specify 0 $flags: msg_ipc_nowait If the queue is null to return directly (not blocked), msg_except Msg_noerror See manual */$data = msg_receive ($q, 0, $type, $msg);
Var_dump ($data);
echo "\ n";
Var_dump ($type);
echo "\ n";
Var_dump ($msg);

 echo "\ n";

Queue status information: specific reference manual

Array
(
[msg_perm.uid] => 1015
[Msg_perm.gid] =>
[Msg_perm.mode] => 438
[Msg_stime] => 0
[msg_rtime] => 0
[msg_ctime] => 1411830331
[Msg_qnum] => 0
[msg_qbytes] => 65536< C10/>[msg_lspid] => 0
[msg_lrpid] => 0
)

Linux under the IPC command to view, with the IPCRM command can be deleted

For more information about PHP interested readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP error and Exception handling method summary", "PHP Programming algorithm Summary" and "PHP object-oriented Program Design Introduction Course"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.