Changeset 305

Show
Ignore:
Timestamp:
12/10/08 02:32:08 (5 years ago)
Author:
tobias382
Message:

Modified the Streams driver to use a blocking socket with a short timeout to prevent CPU and memory thrashing

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/2.0.0/Phergie/Driver/Streams.php

    r301 r305  
    3030     */ 
    3131    private $_debug = false; 
     32 
     33    /** 
     34     * Delay between ticks in microseconds, used to prevent CPU and memory  
     35     * thrashing 
     36     * 
     37     * @var int 
     38     */ 
     39    private $_delay = 50000; 
     40 
     41    /** 
     42     * Sets a delay in microseconds between reads, used to prevent CPU and  
     43     * memory thrashing. 
     44     * 
     45     * @param int $delay 
     46     * @return Phergie_Bot Provides a fluent interface 
     47     */ 
     48    public function setDelay($delay) 
     49    { 
     50        $this->_delay = (int) $delay; 
     51 
     52        return $this; 
     53    } 
    3254 
    3355    /** 
     
    277299            trigger_error('Unable to connect to server: socket error ' . $errno . ' ' . $errstr, E_USER_ERROR); 
    278300        } 
    279         stream_set_blocking($this->_socket, false); 
     301        stream_set_timeout($this->_socket, $this->_delay); 
    280302 
    281303        // Send the password if one is specified