php fread'ing problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TooCrooked
Forum Newbie
Posts: 7
Joined: Fri Oct 27, 2006 6:17 am

php fread'ing problem

Post by TooCrooked »

many thanks!
Last edited by TooCrooked on Thu Jun 07, 2007 3:40 pm, edited 1 time in total.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
TooCrooked
Forum Newbie
Posts: 7
Joined: Fri Oct 27, 2006 6:17 am

Post by TooCrooked »

-- edit

SOLVED!!
Post Reply