How To Communicate Between PHP Scripts (Sample Source Code Included) Come comunicare tra di script PHP (campione di codice sorgente inclusa)
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. Script PHP, come WordPress, phpBB, ecc phpMyAdmin operare nel loro mondo senza più comunicazione tra processi, anche se sono in esecuzione sullo stesso server Apache. However sometimes you need to have a seamless way to communicate between PHP scripts without deadlock or resource contention. Tuttavia a volte è necessario disporre di un unico modo di comunicare tra di script PHP senza stallo o una risorsa contesa. This is where messaging becomes useful. Si tratta di messaggi in cui diventa utile. PHP allows you to easily communicate between scripts running on the same machine. PHP permette di comunicare facilmente fra gli script in esecuzione sulla stessa macchina.
PHP provides a set of function for inter-process communication. PHP fornisce una serie di funzioni per la comunicazione tra processi. They are: Essi sono:
msg_get_queue — Create or attach to a message queue msg_get_queue - Crea o allegare a un messaggio coda
msg_receive — Receive a message from a message queue msg_receive - Ricevere un messaggio da una coda di messaggi
msg_remove_queue — Destroy a message queue msg_remove_queue - distruggere una coda di messaggi
msg_send — Send a message to a message queue msg_send - Invia un messaggio a una coda di messaggi
msg_set_queue — Set information in the message queue data structure msg_set_queue - Imposta le informazioni in coda di messaggi struttura di dati
msg_stat_queue — Returns information from the message queue data structure msg_stat_queue - Restituisce informazioni dalla coda di messaggi struttura di dati
Let’s see an actual example with two scripts which communicate with each other. Vediamo un vero e proprio esempio con due script che comunicano tra di loro. Save the files (preferably with the given names) on your htdocs (/var/www/html on Linux) directory. Salvare il file (preferibilmente con il nome) sul tuo htdocs (/ var / www / html su Linux) directory. First run the msg_send.php to add message to the queue. Prima eseguire il msg_send.php per aggiungere un messaggio alla coda. Then run msg_receive.php to get the messages and display them. Quindi eseguire msg_receive.php per ottenere i messaggi e li visualizza.
File: msg_send.php File: msg_send.php
Notes: This file adds two message to the queue Note: Questo file aggiunge due messaggio alla coda
File: msg_receive.php File: msg_receive.php
Note: This file receives the message and prints them. Nota: Questo file riceve il messaggio e stampe.
The output from the first script will be similar to: L'output del primo script sarà simile a:
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: L'uscita dal secondo script sarà simile a:
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 ) Questo è il messaggio # 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) Questo è il messaggio # 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) Filed under Elencato sotto Enterprise Software Enterprise Software , Headline News Headline News , How To Come , Open Source Software Software open source , PHP , Programming Programmazione , Tech Note Nota tech , Web | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | questo articolo |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |




May 6th, 2008 at 8:41 am 6 maggio 2008, 8:41 am
[...] can be used to store and retrieve data across processes. [...] Può essere utilizzata per memorizzare e recuperare i dati tra processi. This is also another alternative way to communicate between php scripts. Questo è anche un altro modo alternativo per comunicare tra di script PHP. Normally shared memory is used for caching frequently used data in memory for php scripts on the [...] Normalmente memoria condivisa viene utilizzata per il caching dei dati di uso frequente in memoria di script PHP per il [...]