ID: 24066 Updated by: [EMAIL PROTECTED] Reported By: jason at superlink dot net -Status: Open +Status: Feedback Bug Type: Sockets related Operating System: FreeBSD 4.8 PHP Version: 4.3.2
Previous Comments: ------------------------------------------------------------------------ [2003-07-21 10:11:41] [EMAIL PROTECTED] Can you try your example with var_dump($buffer) in your code? socket_read returns boolean(FALSE) on an actual error, and empty string "" when the connecting system has closed the connection. The connection closed is not considered and error, and thus socket_last_error() is 0 (no error) If you don't like this behaivior there is socket_recv, which returns the length of the message returned(0 = connection close), and takes a buf argument of the string, but it does not have the PHP_NORMAL_READ capibility. If this is the problem you should recode tests of socket_read like so if (($buffer = socket_read($socket, 2048, xxx)) === FALSE) { // Error has occured } else if (empty($buffer)) { // client disconnected } else { // do something with data } -Jason ------------------------------------------------------------------------ [2003-06-06 21:50:20] jason at superlink dot net Okay, a few things to add to my post... I wanted to add that my initial assessment that binary_read did not suffer from this issue is false. In my inital test with binary read, I thought that simply watching the socket download data was enough to validate if the issue was with normal_read. There was one glaring diff between normal_read and binary_read -- my software was only able to properly process input data from normal_read. After a bit of tweaking, I made binary_read also function and properly parse input. Once it was processing input, it too had socket disconnects. Without processing input, it's simply reading in data, with processing, it has to check data with a RDBMs, which causes a slight delay between reads. Perhaps this bit of info can help narrow down the problem. Also, I wanted to add that I read the bug report about socket_read() returning an infinate number of "\n" ... (http://bugs.php.net/bug.php?id=21760), that bug is still present in 4.3.2. I had to write a shell script to watch for cpu use over 40% and kill the process. It seems to happen around ~5% of the time. ------------------------------------------------------------------------ [2003-06-06 14:36:06] jason at superlink dot net I'm running a socket connection that needs NORMAL_READ mode enabled. Here is a sample of the socket connection: <?php while(1){ $r = array($socket); if(socket_select($r, $w, $except = NULL, 0)) { if($buffer = socket_read($socket, 2048, PHP_NORMAL_READ)) { $data=trim($buffer); dostuff($data);// do something with the data. } else { // for some reason my socket connection FAILS a lot. die("ERROR: failed to read socket to $remotehost"); } } else { sleep(1); } } ?> In the event of an error, I've been logging the error: socket_strerror(socket_last_error()) The error for the last 5 attempts has returned: uptime: 211 Unknown error: 0 uptime: 439 Unknown error: 0 uptime: 275 Unknown error: 0 uptime: 279 Unknown error: 0 uptime: 395 Unknown error: 0 The socket connection doesn't seem to want to stay alive for long. The error message seems.... very unfriendly. I've tried the program in binary mode (while my program doesn't function with binary mode on, it can still download and read from the socket). In binary mode, the problem does not occur. I've tried NORMAL_READ with and without socket blocking, with the same results (unexplained socket error). this problem seems to have been happening in php 4.3.1 too. Configure Command './configure' '--prefix=/usr/local' '--with-apache=/home/jason/apache_1.3.27' '--enable-exif' '--enable-track-vars' '--with-calendar=shared' '--enable-magic-quotes' '--enable-trans-sid' '--enable-wddx' '--enable-sockets' '--disable-debug' '--enable-gd-native-tt' '--with-zlib' '--enable-inline-optimization' '--enable-memory-limit' '--with-mysql=/usr/local' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24066&edit=1