Bug #15639 Updated: detecting end of UDP packets

From: Date: Wed, 20 Feb 2002 12:02:32 +0000
Subject: Bug #15639 Updated: detecting end of UDP packets
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-658@lists.php.net to get a copy of this message
ID: 15639 Updated by: rip@undernet.org Reported By: rip@undernet.org Status: Open Bug Type: *Network Functions Operating System: All PHP Version: 4.1.1 New Comment: In fact it's worst than that, setting the socket non-blocking makes fread not working on unix/win. Previous Comments: ------------------------------------------------------------------------ [2002-02-20 06:41:24] rip@undernet.org It will kill Windows compatibility, fixing the functions is way better. ------------------------------------------------------------------------ [2002-02-20 06:35:09] wez@php.net What if you set the socket in non-blocking mode? Look for socket_set_blocking in the manual. ------------------------------------------------------------------------ [2002-02-19 22:29:57] rip@undernet.org I am using PHP for UDP stuff (to block access to users based on a DNSBL). With TCP connections, PHP detects the end of a packet. This feature doesn't exist while dealing with UDP but it could exist. ie: If I do a TCP connection and I expect 1 packet (but doesn't know it's size) I'll do this : $fp=fsockopen ("www.stuff.mars", 80, $errno, $errstr, 30); fputs ($fp, "GET / HTTP/1.0\r\nHost: www.stuff.mars\r\n\r\n"); echo fread ($fp,4096); fclose ($fp); Even if the packet isn't 4096 bytes long, it will be returned entirely until fread gets to it's end. With UDP, the end of the packet CAN be detected but IS NOT detected, if you use fgets you get NOTHING and if you use fread you get only the number of bytes you asked for. Worst is that if you set 4096 as the length for fread, since it can't detect the end of a packet, it waits and stay stuck on it until it received 4096 bytes worst of packets. ie : $fp=fsockopen ("udp://boo.stuff.mars", 13, $errno, $errstr, 3); fputs ($fp, "\n"); echo fread ($fp,4096); fclose ($fp); Though I think you could do even better. ie : $fp=fsockopen ("udp://ns.stuff.mars", 53, $errno, $errstr, 3); fputs ($fp, $dns_packet); while ($rcvd=fread($fp,4096)) echo ord($rcvd); fclose ($fp); That's technically doable... I know that there are new socket functions and I could probably use those to do what I want to do. But this report is just about if you want to support UDP sockets as one of the standard features of PHP, then it needs to be well done. Thank you guys, keep up the good work. [ I give $10000 to the first one who come up with a PHP compiler for *nix and Win. ] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15639&edit=1

« previous php.bugs (#658) next »