Stream Functions

From: Date: Sun, 11 Mar 2007 18:15:16 +0000
Subject: Stream Functions
Groups: php.general 
Request: Send a blank email to php-general+get-250243@lists.php.net to get a copy of this message
Hello, I have been trying to get the stream functions to work in PHP. While undoubtedly my problems are due to ignorance I'd appreciate anything helpful anyone would care to say that might alleviate that ignorance. Basically, I have just been trying to get the examples given in the manual to work for the "unix domain". I created the two files below and hit them with my browser. servertest.php -------------- <?php $socket = stream_socket_server("unix://testsock", $errno, $errstr, STREAM_SERVER_BIND); if (!$socket) { echo "ERROR: $errno - $errstr<br />\n"; } else { while ($conn = stream_socket_accept($socket)) { fwrite($conn, date("D M j H:i:s Y\r\n")); fclose($conn); } fclose($socket); } ?> This appears to be working. It creates the socket file in the file system. Then after a long delay, which I presume is waiting for a client request, it returns the following. Warning: stream_socket_accept() [function.stream-socket-accept]: accept failed: Operation timed out in /usr/local/www/data/servertest.php on line 6 Afterward the socket file is left on the file system. socktest.php ------------ <?php $fp = stream_socket_client("unix://testsock", $errno, $errstr); if (!$fp) { echo "ERROR: $errno - $errstr<br />\n"; } else { fwrite($fp, "\n"); echo fread($fp, 26); fclose($fp); } ?> Running this while the server is waiting (or after it has given up) produces the following. Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to unix://testsock (Connection refused) in /usr/local/www/data/socktest.php on line 2 ERROR: 61 - Connection refused If the socket is removed the message changes to "file not found" and if the permissions are changed the message changes to "permission denied". So the program seems to be finding the socket and have permission to access it. Can anyone suggest why the connection might be refused? Best, Craig ------------------------------------------------------
-     Virtual Phonecards - Instant Pin by Email      -
-           Large Selection - Great Rates            -
-     http://speedypin.com/?aff=743&co_branded=1     -
------------------------------------------------------ 
**************************************
*                                    *
*          Craig Spencer             *
*      ccspencer@SoftHome.net        *
*                                    *
**************************************

« previous php.general (#250243) next »