Note Submitter: mindmaster at gmail dot com
----
Hello everybody. Let us supose that some program in PHP
needs to communicate some other program using a filesystem
pipe. Supposing that the pipe is already present in the
filesystem, we need to send this program a message using a
very simple protocol, something like this
--------------------------------
| ID | Length | Message |
--------------------------------
where ID is a numeric identifier, Length is the length of
Message and Message contains a string. What is the best way
to accomplish this ?. On the other side (the program that is
running in background is a Python program that reads a
message when available and executes some code). I tried to
use the pack function but the Python program seems to get
wrong the message. The code for sending a message from PHP :
function send_message_to_pipe ($ID, $length, $msg_body) {
$pipe = fopen ("../../fifo",
"wb");
if ($length == 0)
$packed_msg = pack ("ii",
$ID, $length);
else
$packed_msg = pack
("iic*", $ID, strlen ($msg_body), $message);
fwrite ($pipe, $packed_msg);
fclose ($pipe);
}
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|