OK, this is going to confusing and I hope I can explain:
According to some socket class code I found called 'DQ's turbo socket class' for PHP there is a bug with the 'socket_get_status' function in PHP. It states that calling this function will not return the correct number of unread bytes on a socket. It also gives a simple work around for the bug, just read 0 (zero) bytes from the socket and the socket_get_status function will return the correct number of unread bytes. First of all, I was wondering if anyone else has seen this? I have spent almost two days and have yet to find a bug report or even another coder like myself stating this situation.
Secondly, the work around doesn't work for me. Reading zero bytes is essentially the same as not reading any and it always returns 0 (zero) unread bytes from the socket, which I know is not correct. It does, however, work if I read 1 byte (it will return the correct number of unread bytes minus the one I just read)... of course, before this read I don't know if there is even a byte available so this isn't a good solution (see my next paragraph as to why this isn't good). A catch 22, I need to know how many bytes I can read... but I need to read a byte (that might not even exist) to find out how many are available in the first place...
And last, does anyone know why PHP sockets were coded so sloppily? I hate it when I try to read a single byte to update the 'socket_get_status' function as stated above and the socket just sits there waiting and waiting and waiting... never actually returning becuase that byte doesn't even exist. I mean if I want to read 1024 bytes from a socket and that socket only has 256 to be read, who in there right mind would code the read statement to just "sit and wait" for those extra non-existant bytes to come in.... ahhh.. so disappointing... yet it's probably for some reason beyond my comprehension... I'm just so used to sockets in C/C++. Anyway, its for this reason that reading a single byte to see how many bytes are available to be read from the socket, is not a good solution because it may just sit there and wait... (NOTE: blocking vs. non-blocking made no difference in this situation, nor did having a php script timeout set. When I said it just waited, I meant WAITED... forever... at least until I hit the stop button in my browser...)
If you have any information about this or you know of someone who can help me I would greatly appreciate it.
Thank you,
Robert Knepp
Adelphia Communications
Knowledge Engineer