public function exec($command)
    {
        $command = implode(' ', func_get_args());

        fwrite($this->_fp, str_replace("\n", '\n', $command) . PHP_EOL);

        $answer = fgets($this->_fp); //"ANSWER $bytes" or false if an error occurred
        if (is_string($answer)) {
            if (substr($answer, 0, 7) === 'ANSWER ') {
                $bytes = ((int) substr($answer, 7)) + 1; //+1 because the json-return seems to miss one byte
                if ($bytes > 0) {
                    $bytesRead = 0;
                    $jsonString = '';

                    //Run fread() till we have all the bytes we want
                    //(as fread() can only read a maximum of 8192 bytes from a read-buffered stream at once)
                    do {
                        $jsonString .= fread($this->_fp, $bytes - $bytesRead);
                        $bytesRead = strlen($jsonString);
                    } while ($bytesRead < $bytes);

                    $json = json_decode($jsonString);

                    if (!isset($json->error)) {
                        //Reset error-message and error-code
                        $this->_errorMessage = null;
                        $this->_errorCode = null;

                        //For "status_online" and "status_offline"
                        if (isset($json->result) && $json->result === 'SUCCESS') {
                            return true;
                        }

                        //Return json-object
                        return $json;
                    } else {
                        $this->_errorMessage = $json->error;
                        $this->_errorCode = $json->error_code;
                    }
                }
            }
        }

        return false;
    }
public function exec($command)
    {
        $command = implode(' ', func_get_args());

        fwrite($this->_fp, str_replace("\n", '\n', $command) . PHP_EOL);

        $answer = fgets($this->_fp); //"ANSWER $bytes" or false if an error occurred
        if (is_string($answer)) {
            if (substr($answer, 0, 7) === 'ANSWER ') {
                $bytes = ((int) substr($answer, 7)) + 1; //+1 because the json-return seems to miss one byte
                if ($bytes > 0) {
                    $bytesRead = 0;
                    $jsonString = '';

                    //Run fread() till we have all the bytes we want
                    //(as fread() can only read a maximum of 8192 bytes from a read-buffered stream at once)
                    do {
                        $jsonString .= fread($this->_fp, $bytes - $bytesRead);
                        $bytesRead = strlen($jsonString);
                    } while ($bytesRead < $bytes);

                    $json = json_decode($jsonString);

                    if (!isset($json->error)) {
                        //Reset error-message and error-code
                        $this->_errorMessage = null;
                        $this->_errorCode = null;

                        //For "status_online" and "status_offline"
                        if (isset($json->result) && $json->result === 'SUCCESS') {
                            return true;
                        }

                        //Return json-object
                        return $json;
                    } else {
                        $this->_errorMessage = $json->error;
                        $this->_errorCode = $json->error_code;
                    }
                }
            }
        }

        return false;
    }
public function exec ( $ command ) { $ command = implode ( ' ' , func_get_args ( ) ) ; fwrite ( $ this -> _fp , str_replace ( "\n" , '\n' , $ command ) . PHP_EOL ) ; $ answer = fgets ( $ this -> _fp ) ; //"ANSWER $bytes" or false if an error occurred if ( is_string ( $ answer ) ) { if ( substr ( $ answer , 0 , 7 ) === 'ANSWER ' ) { $ bytes = ( ( int ) substr ( $ answer , 7 ) ) + 1 ; //+1 because the json-return seems to miss one byte if ( $ bytes > 0 ) { $ bytesRead = 0 ; $ jsonString = '' ; //Run fread() till we have all the bytes we want //(as fread() can only read a maximum of 8192 bytes from a read-buffered stream at once) do { $ jsonString .= fread ( $ this -> _fp , $ bytes - $ bytesRead ) ; $ bytesRead = strlen ( $ jsonString ) ; } while ( $ bytesRead < $ bytes ) ; $ json = json_decode ( $ jsonString ) ; if ( ! isset ( $ json -> error ) ) { //Reset error-message and error-code $ this -> _errorMessage = null ; $ this -> _errorCode = null ; //For "status_online" and "status_offline" if ( isset ( $ json -> result ) && $ json -> result === 'SUCCESS' ) { return true ; } //Return json-object return $ json ; } else { $ this -> _errorMessage = $ json -> error ; $ this -> _errorCode = $ json -> error_code ; } } } } return false ; }
Executes a command on the telegram-cli. Line-breaks will be escaped, as telgram-cli does not support them.

@param string $command The command. Command-arguments can be passed as additional method-arguments.

@return object|boolean Returns the answer as a json-object or true on success, false if there was an error.
Executes a command on the telegram - cli . Line - breaks will be escaped as telgram - cli does not support them .