note 77446 rejected from function.pack by cece

From: Date: Fri, 31 Aug 2007 11:58:25 +0000
Subject: note 77446 rejected from function.pack by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129936@lists.php.net to get a copy of this message
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); }

« previous php.notes (#129936) next »