Hey all, new here..
I seem to be having problems with how fread() and fgets() works on socket streams.
I've found that if I read past the end of the socket buffer using either fgets() or fread() the script will wait for the timeout of that socket set by stream_set_timeout() before returning the buffer.
I've tried setting stream_set_blocking() to false but that gives me undesired results because fgets() and fread() won't wait for anything to arive in the buffer (if it's blank) before returning it, thus returning false when I want it to wait for something.
If I set the socket timeout to 2 seconds it will wait 2 seconds before returning the buffer if the length specified in fgets($sock, 1024) and fread($sock, 1024) is longer than the length of the buffer.
Needless to say this is undesirable as it really impacts the preformance and speed of the script.
What I need is a way to know what the actuall length of the buffer (unread chars). If I can accomplish this I will be able to know if it should wait for more chars to appear in the buffer or just return what's already in it. Make sense?
I've tried using fgetc() while looping, but that doesn't work for what I need either.
Anyone have any answers to this problem?
Thanks in advance. =).
- Jeremy