You may need to set a socket timeout value (use socket_set_timeout() or stream_set_timeout() with something reasonable, say 1 second) which continues the script if no more data is being received. Read more about this here :
http://www.php.net/manual/en/function.fsockopen.php and
http://www.php.net/manual/en/function.socket-set-timeout.php
I have also verified that some versions of PHP (<4.2) will hang up a script (up to the script timeout) if a packet request is blocked by a firewall on the other end.
You can read more about this in a bug report submitted in February.
http://bugs.php.net/bug.php?id=15639
Hope it works out.
Regards,
Neil Smith.
At 08:04 02/01/2003 +0000, you wrote:
Message-ID: <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Reply-To: "Torben Dehn" <[EMAIL PROTECTED]> From: "Torben Dehn" <[EMAIL PROTECTED]> Date: Wed, 1 Jan 2003 17:34:05 +0100 Subject: UDP packetHello ! I am very new to PHP so please don't laugh if my code really sucks ;=) What i am trying to do is : 1) Opening an UDP connectión to a server (That works allright) 2) Making a query to the server (That works allright) 3) Recieve an unknow number of UDP packets with an unknown packet size (This is my problem) I don't know the packet size and i don't know how many packets the server will return... Take a look at the WHILE loop because thats where it "hangs". If i remove the WHILE loop and just make a fread($socket,1024) it will return some data. My questions are as follow : 1) How can i make sure that ALL data has been recieved ? 2) Is it possible to read each UDP packet into it's own variable (array) ??? I would be very happy if someone could answer one or all question. <? $ip = "192.246.40.65"; $port = 27950; $command = "˙˙˙˙getservers 60 empty full"; $data = ''; Echo "Connecting to Master Server : $ip:$port<br>"; $socket = fsockopen("udp://$ip",$port,$errno,$errstr,2); if (!$socket) { echo "There was an error connecting to the Master Server<br>"; echo "Error returned was : $errorno and $errostr"; exit; } //Socket error else { echo "Connection established ..<br>"; If (!fwrite($socket,$command)) { echo "There was an error querying the master server .."; exit; } //Fwrite error echo "Query complete ..<br>"; while (!feof($socket)) { echo "Reading data ..<br>"; $data .= fread($socket,4096); } //End of read section echo "$data<br>"; fclose($socket); echo "Connection closed ..<br>"; } //End of main loop ?>
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php