• Welcome to Valhalla Legends Archive.
 

PHP Help with Battle.net

Started by UnderCover, November 16, 2003, 06:51 PM

Previous topic - Next topic

UnderCover

i know wut explode does but i can't seem to figure out the fread.

For some reason fread cuts or just doesn't display all then data.

If anyone can help me that would eb great.

Banana fanna fo fanna

Quote from: UnderCover on November 23, 2003, 08:40 AM
i know wut explode does but i can't seem to figure out the fread.

For some reason fread cuts or just doesn't display all then data.

If anyone can help me that would eb great.

It would help if you actually read what people were saying.

UnderCover

is this a good loop to get data.  I tested it and it worked fine the only problem was that it kept timing out :(


while ( !feof( $socket ) ) {
  $ret = fgets( $socket, 4096 );
  echo "<li>$ret</li>";
}


Banana fanna fo fanna

Well, if it has a problem, then it isn't.

Grok

#64
Quote from: St0rm.iD on November 23, 2003, 11:31 AM
Well, if it has a problem, then it isn't.

And to summarize the last 30 replies,

Your loop, as implemented, has a problem.  The problem is:
In case you missed the advance notice .. The problem is:
I'm about to tell you what's wrong ... The problem is:
Here comes a real good clue ... The problem is:
Pay attention now .... The problem is:
Here it is ... The problem is:
The problem is:

If your data contains incomplete data (a line from chat without a newline at the end) your code does not take that into consideration.  It puts that last, incomplete line into the final array element which was created by explode().  By then processing that final element as if it were a complete line of chat, you are getting the visible impression of reality -- that TCP breaks up data wherever the hell it wants, and leaves it up to you to make sure the contents are complete.

How to fix?  Easy.  Only allow explode to operate on your buffer's contents up to the final newline character.  Anything after that character you need to put back in the buffer.

After you fix that, you'll realize your program has an additional, major, structural problem.

|