utexas_pjm Posted May 19, 2007 Share Posted May 19, 2007 For the past couple of weeks I've been writing a webserver in PHP. Everything has been going relativeley smooth, until recently when I noticed that sometimes the HTTP request is getting truncated: POST /test.php HTTP/1.1 Host: www.patrickmizer.com:9191 User-Agent: Mozilla/5.0 (X11; you; Linux i686 (x86_64); en-US; rv:1.8.1.1) Gecko/20061208 Firefox/2.0.0.1 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.patrickmizer.com:9191/test.php Content-Type: application/x-www-form-urlencoded Content-Length: 28 height=0&width=0&submitted=1 POST /test.php HTTP/1.1 Host: www.patrickmizer.com:9191 User-Agent: Mozilla/5.0 (X11; you; Linux i686 (x86_64); en-US; rv:1.8.1.1) Gecko/20061208 Firefox/2.0.0.1 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.patrickmizer.com:9191/test.php I've tracked the problem down to the socket_read function. I'm calling it from within a socket wrapper class that I've written. The code is berlow: <?php // ... public function readBinary($size = 4096) { if (false === ($inputl = socket_read($this->socket, $size, PHP_BINARY_READ))) { throw new Exception("Could not read data from socket."); return false; } return trim($input); } // ... ?> I think what is happening is that all of the data hasn't been received by the socket before it is read from the socket_read function. I say this, because if I add a sleep(1) call as the first line in the readBinary method this problem goes away. Obviously this isn't a viable solution, any suggestions? Thanks, Patrick P.S. The problem can be seen here (on the POST): http://www.patrickmizer.com:9191/test.php Link to comment https://forums.phpfreaks.com/topic/52162-interesting-socket_read-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.