Page 1 of 1
php fread'ing problem
Posted: Sat Oct 28, 2006 10:44 pm
by TooCrooked
many thanks!
Posted: Sun Oct 29, 2006 4:41 am
by Ollie Saunders
I've never done anything involving sockets before so I'm not really much use to you but considering your post and its over-specification I urge you, if you wish to benefit from others helping you, to explain in simple terms what you are trying to do and how you are going about doing it. You should also show the simplest possible code recreation of the problem you are experiencing. Both of these are necessary for others to see and understand the problem and thus find a solution.
Posted: Sun Oct 29, 2006 4:59 am
by volka
TooCrooked wrote:function GetByte() {return Ord(fread($this->sp, 1));}
Now the server isn't sending any data or something else goes wrong, what does this function do? fread() returns false or "nothing", and Ord(false) returns 0, GetByte() returns 0. Nothing in the script notices that no data was read but a timeout occured.
scenario: you ping a server that needs some time to handle the request.
$this->GetInt32(); is your first read operation. It calles GetByte() four times. The first GetByte() has a timeout -> return 0, GetInt32() is happy, it gets a byte. Now the server is ready to send the data. GetByte() #2 reads the first byte of the actual data. From here on everything is shifted one byte.
If you use php5 you can test the return value of fread() and then throw an exception. Do you use php5?
Posted: Sun Oct 29, 2006 10:50 am
by TooCrooked
-- edit
SOLVED!!