Api/Odr.php
/**
     * Executes cURL request and return result and error
     *
     * @param string $url    Where send request
     * @param string $method What method should be called
     * @param array  $data   Additional data to send
     *
     * @return Api_Odr
     *
     * @throws Api_Odr_Exception
     *
     * @protected
     */
Executes cURL request and return result and error
@param string $url    Where send request
@param string $method What method should be called
@param array  $data   Additional data to send





@protected
Executes cURL request and return result and error @param string $url Where send request @param string $method What method should be called @param array $data Additional data to send @protected
protected function _execute($url = '', $method = self::DEFAULT_METHOD, array $data = array())
    {
        $this->_resultBody    = null;
        $this->_resultHeaders = null;
        if (!is_string($method) || $method === '') {
            $method = self::DEFAULT_METHOD;
        }
        $method = strtoupper($method);
        $host   = $this->getUrl();
        if (!is_string($url) || $url === '') {
            $url = $host;
        }
        if (strpos($url, '/') === 0) {
            $url = $host . '/' . trim($url, '/') . '/';
        }
        if (strpos($url, $host) !== 0) {
            throw new Api_Odr_Exception('Wrong host for URL (' . $url . ')');
        }
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST,  $method);
        curl_setopt($ch, CURLOPT_HEADER,         true);
        if (count($data) > 0) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        }
        $headers = array();
        if (count($this->_headers) > 0) {
            foreach ($this->_headers as $k => $v) {
                $headers[] = $k . ': ' . $v;
            }
        }
        $headers[] = 'Expect:'; 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $result = curl_exec($ch);
        list($resultHeaders, $resultBody) = explode("\r\n\r\n", $result, 2);
        $this->_error = curl_error($ch);
        if (empty($this->_error)) {
            $this->_resultBody    = json_decode($resultBody, true);
            $this->_resultHeaders = $this->parseHeaders($resultHeaders);
        }
        curl_close($ch);
        usleep(500);
        if (!empty($this->_error)) {
            throw new Api_Odr_Exception($this->_error);
        }
        return $this;
    }
protected function _execute ( $ url = '' , $ method = self :: DEFAULT_METHOD , array $ data = array ( ) ) { $ this -> _resultBody = null ; $ this -> _resultHeaders = null ; if ( ! is_string ( $ method ) || $ method === '' ) { $ method = self :: DEFAULT_METHOD ; } $ method = strtoupper ( $ method ) ; $ host = $ this -> getUrl ( ) ; if ( ! is_string ( $ url ) || $ url === '' ) { $ url = $ host ; } if ( strpos ( $ url , '/' ) === 0 ) { $ url = $ host . '/' . trim ( $ url , '/' ) . '/' ; } if ( strpos ( $ url , $ host ) !== 0 ) { throw new Api_Odr_Exception ( 'Wrong host for URL (' . $ url . ')' ) ; } $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , $ method ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; if ( count ( $ data ) > 0 ) { curl_setopt ( $ ch , CURLOPT_POSTFIELDS , json_encode ( $ data ) ) ; } $ headers = array ( ) ; if ( count ( $ this -> _headers ) > 0 ) { foreach ( $ this -> _headers as $ k => $ v ) { $ headers [ ] = $ k . ': ' . $ v ; } } $ headers [ ] = 'Expect:' ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; $ result = curl_exec ( $ ch ) ; list ( $ resultHeaders , $ resultBody ) = explode ( " \r \n \r \n " , $ result , 2 ) ; $ this -> _error = curl_error ( $ ch ) ; if ( empty ( $ this -> _error ) ) { $ this -> _resultBody = json_decode ( $ resultBody , true ) ; $ this -> _resultHeaders = $ this -> parseHeaders ( $ resultHeaders ) ; } curl_close ( $ ch ) ; usleep ( 500 ) ; if ( ! empty ( $ this -> _error ) ) { throw new Api_Odr_Exception ( $ this -> _error ) ; } return $ this ; }
Executes cURL request and return result and error
 @param string $url    Where send request
 @param string $method What method should be called
 @param array  $data   Additional data to send
Executes cURL request and return result and error @param string $url Where send request @param string $method What method should be called @param array $data Additional data to send
// Prevent cURL from sending HTTP/1.1 100 Continue (thanks to @githubbauman) // Too much request at a time can ban us