Loop Just keeps looping

THIS LOOP GOES ON FOREVER!!!

[php]$sec = 0;
while ( $sec <= 10 )
{
if ( inotify_queue_len($inotify) > 0 )
{
$i = fopen($in, ‘r+’);

        fwrite($shell,    fread($i, filesize($in)));
                    
        ftruncate($i, 0);
        fclose($i);
        
        while ( inotify_read($inotify) ) {}
        
        //$sec += 1;        
    }
    
    fwrite($o, fread($shell, 4096));
    
    sleep(1);
    $sec += 5;    
}[/php]

but this one doesn’t

[php]$sec = 0;
while ( $sec <= 10 )
{
if ( inotify_queue_len($inotify) > 0 )
{
$i = fopen($in, ‘r+’);

        fwrite($shell,    fread($i, filesize($in)));
                    
        ftruncate($i, 0);
        fclose($i);
        
        while ( inotify_read($inotify) ) {}
        
        //$sec += 1;        
    }
    
    fwrite($o, fread($shell, 4096));
    
    sleep(1);
    $sec = 15;    
}[/php]

I don’t get it??? I’m probably making a really stupid mistake please point it out.

Obviously, first iteration of outer loop run smoothly (in both your versions), but during this first iteration value $inotify triggers, and on the second iteration of outer loop you get into endless loop here:

[php]while ( inotify_read($inotify) ) {}[/php]

Your second version works only because you not let second iteration happen by setting $sec = 15.

That isn’t what was happening but thanks for the effort.

I had the stream $shell set to blocking because in a tutorial i read it said to do that. So fread() was hanging waiting for more input.

Sponsor our Newsletter | Privacy Policy | Terms of Service