Changeset 105

Show
Ignore:
Timestamp:
03/02/08 21:35:46 (5 years ago)
Author:
Seldaek
Message:

* Changed the Timeout detection to a hand-crafted one since set_stream_timeout seems to produce bugs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Phergie/Driver/Streams.php

    r103 r105  
    131131 
    132132        if ($this->getIni('timeout')) { 
    133                 stream_set_timeout($this->socket, $this->getIni('timeout') * 60); 
     133                $timeout = $this->getIni('timeout') * 60; 
    134134        } elseif ($this->getIni('keepalive')) { 
    135                 stream_set_timeout($this->socket, 400); 
     135                $timeout = 600; 
     136                } else { 
     137                        $timeout = false; 
    136138                } 
     139                $lastPacket = time(); 
    137140 
    138141        unset($port); 
     
    176179                $buffer = fgets($this->socket, 512); 
    177180 
    178                                 $checkTimeout = stream_get_meta_data($this->socket); 
    179                                 if ($checkTimeout['timed_out'] === true) { 
    180                                         $this->debug('Timed out'); 
    181                         foreach ($this->plugins as $plugin) { 
    182                             $plugin->shutdown(); 
    183                         } 
    184                                         break 2; 
     181                                // Check if we timed out 
     182                                if ($timeout !== false) { 
     183                                        // Reset last packet timestamp if we received something 
     184                                        if (!empty($buffer)) { 
     185                                                $lastPacket = time(); 
     186                                        } 
     187                                        // Timed out, exit 
     188                                        if ($lastPacket < (time() - $timeout)) { 
     189                                                $this->debug('Timed out'); 
     190                                foreach ($this->plugins as $plugin) { 
     191                                    $plugin->shutdown(); 
     192                                } 
     193                                                break 2; 
     194                                        } 
    185195                                } 
    186196            }