PHP sockets/daemon problem
| From: | Josh Levine | Date: | Wed, 26 Jun 2002 17:32:39 +0000 |
| Subject: | PHP sockets/daemon problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-104017@lists.php.net to get a copy of this message | ||
I'm trying to write a simple PHP script that communicates with a daemon
running on the same server.
Basically, the daemon just accepts an integer and returns an integer:
[josh@jlevine-research josh]$ telnet 127.0.0.1 60324
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
9
25Connection closed by foreign host.
When I try doing this with PHP, however, the output is 2[]5 (where [] ==
a small square symbol).
Here is the script:
<?php
$fp = fsockopen("127.0.0.1", 60324, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br>\n";
} else {
socket_set_blocking ($fp, 1);
socket_set_timeout($fp, 200);
fwrite($fp,"9\n");
$return = fread($fp,4);
echo $return;
fclose($fp);
}
?>
I've tried various string format and type-casting functions with no
results (usually just returns nothing after formatted).
Any ideas?
Thanks in advance,
Josh Levine