ID: 15639
Updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
-Status: Open
+Status: Feedback
Bug Type: *Network Functions
Operating System: All
PHP Version: 4.1.1
New Comment:
What if you set the socket in non-blocking mode?
Look for socket_set_blocking in the manual.
Previous Comments:
------------------------------------------------------------------------
[2002-02-19 22:29:57] [EMAIL PROTECTED]
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