<commit_before><?php

/**
 * worker slave using remote streams in order to communicate with master
 * 
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2011, <NAME>
 * @license http://www.opensource.org/licenses/mit-license MIT License
 * @package Worker
 * @version v0.0.1
 * @link https://github.com/clue/Worker
 */
class Worker_Communicator_Stream extends Worker_Communicator{
    /**
     * connection timeout
     * 
     * @var float
     */
    const TIMEOUT_CONNECTION = 30;
    
    /**
     * stream resource handle
     * 
     * @var resource
     */
    private $stream;
    
    /**
     * instanciate new remote connection to master with given address
     * 
     * @param string|int|NULL|resource $address hostname(+port),port or NULL=default address
     */
    public function __construct($address){
        if(is_resource($address)){
            $this->stream = $address;
        }else{
            $hostname = 'localhost';
            $port     = 12345;
            if(is_int($address)){
                $port = $address;
            }else if(strpos($address,':') !== false){
                $temp = explode(':',$address,2);
                $hostname = $temp[0];
                $port = (int)$temp[1];
            }else if(is_string($address)){
                $hostname = $address;
            }
            
            $errstr = NULL; $errno = NULL;
            $this->stream = fsockopen($hostname,$port,$errno,$errstr,self::TIMEOUT_CONNECTION);
            if($this->stream === false){
                throw new Worker_Exception('Unable to open socket to '.Debug::param($hostname).':'.Debug::param($port).' : '.Debug::param($errstr));
            }
        }
    }
    
    public function close(){
        fclose($this->stream);
    }
    
    public function getStreamRead(){
        return $this->stream;
    }
    
    public function getStreamWrite(){
        return $this->stream;
    }
}
<commit_msg>Hide PHP warning when connection fails (see Exception)<commit_after><?php

/**
 * worker slave using remote streams in order to communicate with master
 * 
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2011, <NAME>
 * @license http://www.opensource.org/licenses/mit-license MIT License
 * @package Worker
 * @version v0.0.1
 * @link https://github.com/clue/Worker
 */
class Worker_Communicator_Stream extends Worker_Communicator{
    /**
     * connection timeout
     * 
     * @var float
     */
    const TIMEOUT_CONNECTION = 30;
    
    /**
     * stream resource handle
     * 
     * @var resource
     */
    private $stream;
    
    /**
     * instanciate new remote connection to master with given address
     * 
     * @param string|int|NULL|resource $address hostname(+port),port or NULL=default address
     */
    public function __construct($address){
        if(is_resource($address)){
            $this->stream = $address;
        }else{
            $hostname = 'localhost';
            $port     = 12345;
            if(is_int($address)){
                $port = $address;
            }else if(strpos($address,':') !== false){
                $temp = explode(':',$address,2);
                $hostname = $temp[0];
                $port = (int)$temp[1];
            }else if(is_string($address)){
                $hostname = $address;
            }
            
            $errstr = NULL; $errno = NULL;
            $this->stream = @fsockopen($hostname,$port,$errno,$errstr,self::TIMEOUT_CONNECTION);
            if($this->stream === false){
                throw new Worker_Exception('Unable to open socket to '.Debug::param($hostname).':'.Debug::param($port).' : '.Debug::param($errstr).' (code '.Debug::param($errno).')');
            }
        }
    }
    
    public function close(){
        fclose($this->stream);
    }
    
    public function getStreamRead(){
        return $this->stream;
    }
    
    public function getStreamWrite(){
        return $this->stream;
    }
}

{'fraction_non_alphanumeric': 0.14184576485461442, 'fraction_numerical': 0.008596713021491783, 'mean_word_length': 2.026778882938026, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '901290', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1111, 'n_words': 253}