#43325 [Opn->Fbk]: feof() hangs on UDP stream

From: Date: Tue, 20 Nov 2007 08:44:44 +0000
Subject: #43325 [Opn->Fbk]: feof() hangs on UDP stream
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119865@lists.php.net to get a copy of this message
ID: 43325 Updated by: jani@php.net Reported By: mertcan at dpozitif dot com -Status: Open +Status: Feedback Bug Type: Streams related Operating System: Centos 5.0 PHP Version: 5.2.5 New Comment: That's still just a piece of the script, a proper test script starts with <?php and ends in ?> and can be just copy'pasted and run.. Previous Comments: ------------------------------------------------------------------------ [2007-11-19 17:19:22] mertcan at dpozitif dot com i gave $tanim in function use: function rcon_komut($komut, $rcon_pass, $ip, $port) { $msg = "ÿÿÿÿchallenge rcon"; $fp = fsockopen("udp://".$ip,$port, $errno, $errstr); stream_set_blocking($fp, 0); fputs($fp, $msg, strlen($msg)); $response = fgets($fp, 1024); $challenge = substr($response, 19, strlen($response) - 20); $msg="ÿÿÿÿrcon".$challenge."\"".$rcon_pass."\"".$komut.chr(0); fputs($fp, $msg, strlen($msg)); while (!feof($fp)) $response .= fgets($fp, 32); fclose ($fp); $response = substr($response, 6, strlen($response)-6); return $response; } ------------------------------------------------------------------------ [2007-11-19 16:31:10] jani@php.net Well, can you give a script that has some possibility of working properly? In the give script you have at least one variable which is not set anywhere: $komut ------------------------------------------------------------------------ [2007-11-19 14:56:21] mertcan at dpozitif dot com It still hangs: $fp = fsockopen("udp://".$ip,$port, $errno, $errstr); stream_set_blocking($fp, 0); ------------------------------------------------------------------------ [2007-11-19 13:29:07] jani@php.net Shouldn't you make the stream non-blocking? Try adding this after fsockopen: stream_set_blocking($fp, false); ------------------------------------------------------------------------ [2007-11-18 23:12:34] mertcan at dpozitif dot com Description: ------------ Using feof on UDP hangs. It should give true or false, in my example it should give true but it hangs. I've tried many ways but it always hangs. Reproduce code: --------------- $msg = "ÿÿÿÿchallenge rcon"; $fp = fsockopen("udp://62.68.207.16",27015, $errno, $errstr); fputs($fp, $msg, strlen($msg)); $response = fgets($fp, 1024); $challenge = substr($response, 19, strlen($response) - 20); $msg = "ÿÿÿÿrcon ".$challenge." \"123456\" ".$komut.chr(0); fputs($fp, $msg, strlen($msg)); echo feof($fp) ? 'true':'false'; $response .= fgets($fp, 32); fclose ($fp); Expected result: ---------------- true Actual result: -------------- hangs ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43325&edit=1

« previous php.bugs (#119865) next »