|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-06-06 14:36 UTC] 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'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 22:00:02 2025 UTC |
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