Topic: PHP while loop problem

This is being used for an IRC client..

while (true)
        {
            $query = mysql_query("SELECT * FROM rows WHERE session_id='".$config['session_id']."'") or die(mysql_error());
            if (mysql_num_rows($query)) {
                while ($row = mysql_fetch_assoc($query)) {
                    cmd_send(prep_text($row['message'], $row['channel']));
                }           
            }
            mysql_query("DELETE FROM rows WHERE session_id='".$config['session_id']."'");
            echo "blah\n";

            $con['buffer']['all'] = trim(fgets($con['socket'], 4096));
            echo $con['buffer']['all']."\n";
           
            if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
                cmd_send('PONG :'.substr($con['buffer']['all'], 6));

            } elseif ($old_buffer != $con['buffer']['all']) {
                // make sense of the buffer
                parse_buffer();
               
               
            }
            if (feof($con['socket']))
                break;
            $old_buffer = $con['buffer']['all'];
        }

It SHOULD echo blah constantly, as it is in the while loop, but it doesn't. Instead, it only echo's "blah" when the socket receives data.

I've tried to figure this out for a while now, and I can't. It just makes no sense to me...
So, if someone could please help me, I would highly appreciate it big_smile

Indocron
$theQuestion = (2*b) || !(2*b);

Re: PHP while loop problem

Okay, according to Mediator, fgets waits until it receives data to continue.
I need some way around this... really really bad.
Maybe something like if (fgets(...)) ?

Indocron
$theQuestion = (2*b) || !(2*b);

Re: PHP while loop problem

You could set a timeout on the stream, obviously it is not ideal, but as far as im aware there isn't a way to check if there is data to be read or not.

http://uk.php.net/manual/en/function.st … imeout.php