PHP scripts such as WordPress, phpBB, phpMyAdmin etc. operate in their own world without much inter-process communication, even if they are running on the same Apache server. PHPスクリプトなどのWordPress 、 phpBBのなら、 phpMyAdmin等の動作させる独自の世界を多くのプロセス間通信、たとえ彼らは同じApacheサーバ上で実行されています。 However sometimes you need to have a seamless way to communicate between PHP scripts without deadlock or resource contention.しかしあるとき、あなたを必要とするPHPスクリプトの間のシームレスな通信方法をデッドロックやリソースの競合なしです。 This is where messaging becomes useful.これにはメッセージが役に立つ。 PHP allows you to easily communicate between scripts running on the same machine. PHPのスクリプトを使用すると簡単にコミュニケーションの間に同じマシン上で実行されています。

PHP provides a set of function for inter-process communication. PHPの関数では、セットの間のプロセス間通信します。 They are:彼らは:

msg_get_queue — Create or attach to a message queue するmsg_get_queue -メッセージキューを作成またはそれにアタッチする
msg_receive — Receive a message from a message queue msg_receive -メッセージキューを確認するメッセージが表示
msg_remove_queue — Destroy a message queue msg_remove_queue -メッセージキューを台無しにする
msg_send — Send a message to a message queue msg_send -メッセージキューにメッセージを送信する
msg_set_queue — Set information in the message queue data structure msg_set_queue -メッセージキューの情報を設定するデータ構造
msg_stat_queue — Returns information from the message queue data structure msg_stat_queue -戻り値のデータ構造からの情報メッセージキュー

Let’s see an actual example with two scripts which communicate with each other.ええと、実際の例を2つのスクリプトで互いに意思疎通をします。 Save the files (preferably with the given names) on your htdocs (/var/www/html on Linux) directory.保存し、ファイル(できれば、与えられた名前)を使用してhtdocs (の/ var / www / htmlのLinux上)ディレクトリにコピーします。 First run the msg_send.php to add message to the queue.最初に実行してメッセージをキューに追加するmsg_send.phpです。 Then run msg_receive.php to get the messages and display them. msg_receive.phpを取得するにメッセージを入力し、実行し、表示します。


File: msg_send.php ファイル: msg_send.php
Notes: This file adds two message to the queue注意:このファイルの2つのメッセージをキューに追加


File: msg_receive.php ファイル: msg_receive.php
Note: This file receives the message and prints them.注:このファイルを受信するメッセージを表示し、プリントします。


The output from the first script will be similar to:の最初のスクリプトからの出力は、次のように:

 Array (     [msg_perm.uid] => 48     [msg_perm.gid] => 48     [msg_perm.mode] => 438     [msg_stime] => 1194961462     [msg_rtime] => 1194961436     [msg_ctime] => 1194961406     [msg_qnum] => 2     [msg_qbytes] => 16384     [msg_lspid] => 9474     [msg_lrpid] => 9472 )配列( [ msg_perm.uid ] = > 48 [ msg_perm.gid ] = > 48 [ msg_perm.mode ] = > 438 [ msg_stime ] = > 1194961462 [ msg_rtime ] = > 1194961436 [ msg_ctime ] = > 1194961406 [ msg_qnum ] = > 2 [ msg_qbytes ] = > 16384 [ msg_lspid ] = > 9474 [ msg_lrpid ] = > 9472 ) 

The output from the second script will be similar to: 2番目のスクリプトからの出力は、次のように:

 This is message #1 Array (     [msg_perm.uid] => 48     [msg_perm.gid] => 48     [msg_perm.mode] => 438     [msg_stime] => 1194961462     [msg_rtime] => 1194961471     [msg_ctime] => 1194961406     [msg_qnum] => 1     [msg_qbytes] => 16384     [msg_lspid] => 9474     [msg_lrpid] => 9476 ) This is message #2 Array (     [msg_perm.uid] => 48     [msg_perm.gid] => 48     [msg_perm.mode] => 438     [msg_stime] => 1194961462     [msg_rtime] => 1194961471     [msg_ctime] => 1194961406     [msg_qnum] => 0     [msg_qbytes] => 16384     [msg_lspid] => 9474     [msg_lrpid] => 9476 )これは、メッセージが表示さ# 1の配列( [ msg_perm.uid ] = > 48 [ msg_perm.gid ] = > 48 [ msg_perm.mode ] = > 438 [ msg_stime ] = > 1194961462 [ msg_rtime ] = > 1194961471 [ msg_ctime ] = > 1194961406 [ msg_qnum ] = > 1 [ msg_qbytes ] = > 16384 [ msg_lspid ] = > 9474 [ msg_lrpid ] = > 9476 )これは、メッセージが表示さ# 2配列( [ msg_perm.uid ] = > 48 [ msg_perm.gid ] = > 48 [ msg_perm 。モード] = > 438 [ msg_stime ] = > 1194961462 [ msg_rtime ] = > 1194961471 [ msg_ctime ] = > 1194961406 [ msg_qnum ] = > 0 [ msg_qbytes ] = > 16384 [ msg_lspid ] = > 9474 [ msg_lrpid ] = > 9476 )