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 - Destroy очереди сообщений
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 - Set информации в очереди сообщений структуры данных
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. Давайте посмотрим, фактический пример с двумя сценариями, которые общаться друг с другом. 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 Примечание: Данный файл добавляет два сообщения на очереди


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 ) 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) 

The output from the second script will be similar to: Выход из второго сценария будет аналогична:

 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 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) Это сообщение # 2 Array ([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)