note 77446 added to function.pack
| From: | mindmasteratgmaildotcom at osu1 dot php dot net | Date: | Thu, 30 Aug 2007 03:43:45 +0000 |
| Subject: | note 77446 added to function.pack | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129894@lists.php.net to get a copy of this message | ||
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);
}
----
Server IP: 201.216.232.3
Probable Submitter: 201.255.61.128
----
Manual Page -- http://www.php.net/manual/en/function.pack.php
Edit -- https://master.php.net/note/edit/77446
Del: integrated -- https://master.php.net/note/delete/77446/integrated
Del: useless -- https://master.php.net/note/delete/77446/useless
Del: bad code -- https://master.php.net/note/delete/77446/bad+code
Del: spam -- https://master.php.net/note/delete/77446/spam
Del: non-english -- https://master.php.net/note/delete/77446/non-english
Del: in docs -- https://master.php.net/note/delete/77446/in+docs
Del: other reasons-- https://master.php.net/note/delete/77446
Reject -- https://master.php.net/note/reject/77446
Search -- https://master.php.net/manage/user-notes.php