ID: 20397
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Feedback
Bug Type: Sockets related
Operating System: linux
PHP Version: 4.2.3
New Comment:
Can you clarify what the problem is?
And can you trim down the code to something small, preferably using
some standard service so that we can reproduce it here?
$fp = fsockopen(...)
fwrite($fp, "foo");
$data = fread($fp, 1);
Tell us what you expect to happen, and what does actually
happen. Is PHP returning too soon, waiting too long?
UDP is a connectionless protocol, so you have to write your scripts to
take that fact into account.
Also, please only test with a PHP 4.3 RC as this is where any fix would
be made (4.2 is very old code compared to 4.3).
Previous Comments:
------------------------------------------------------------------------
[2002-11-20 07:59:22] [EMAIL PROTECTED]
seems the problem is with fread and socket timeout changed to fgetc and
all is well works the way it should
but fread and udp and socket timeout has some problem.
------------------------------------------------------------------------
[2002-11-13 07:36:51] [EMAIL PROTECTED]
Here is a snippet of the code, I tried set_socket_timeout it didnt
work. this is using socket_set_timeout and it doesnt work either.
function getrules()
{
$address="udp://".$this->ip;
$this->socket=fsockopen($address,$this->port,$this->errno,$this->errstr,5);
if(!$this->socket)
{
exit();
}
set_socket_blocking($this->socket, FALSE);
$outstring="����rules";
fwrite($this->socket,$outstring);
$inbyte=$this->waitstart();
$this->rules[firstchunk]=$inbyte . fread($this->socket,3);
$this->rules[rulesbyte]=$this->getchar();
$this->rules[number]=$this->getint();
for($loop=0;$loop<$this->rules[number];$loop++)
{
$this->rules[rules][$loop][name]=$this->getstring();
$this->rules[rules][$loop][value]=$this->getstring();
//$rulename=getstring;
//$ruleval=getstring;
//$this->rules[rules][$loop][name]=$rulename;
//$this->rules[rules][$loop][value]=$ruleval;
}
fclose($this->socket);
return;
}
function waitstart()
{
socket_set_timeout($this->socket, 0, 500);
$inbyte=fread($this->socket,1);
while($inbyte=="")
{
socket_set_timeout($this->socket, 0, 500);
$inbyte=fread($this->socket,1);
}
return $inbyte;
}
function getstring()
{
socket_set_timeout($this->socket, 0, 500);
$inbyte=fread($this->socket,1);
while($inbyte != "\0")
{
$string.=$inbyte;
socket_set_timeout($this->socket, 0, 500);
$inbyte=fread($this->socket,1);
}
return $string;
}
------------------------------------------------------------------------
[2002-11-12 13:44:27] [EMAIL PROTECTED]
How are you setting the timeout value? The timeout value specified as
the 5th argument to fsockopen() is only the timeout for the connection
initiation. The read/write timeouts should be set via the
stream_set_timeout() (CVS) or set_socket_timeout() in older versions.
------------------------------------------------------------------------
[2002-11-12 11:33:34] [EMAIL PROTECTED]
I create a udp connection using fsockopen and before all my reads I set
a socket timeout. The timeouts are never respected, because if this
situation arises, I time out with FATAL ERROR: timed out greater than
30 sec msg from the server.
I want to be able to catch this before reaching the FATAL ERROR.
The behaviour can be seen at our website http://www.xtreme-forces.com
Click on the SERVERS button to see the page in action. 60% of the time
it works great rest it will Fatal, hit the Refresh to cause the error
to occur quicker.
I can make the code available upon request.
thanks
Vito
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20397&edit=1