public function makeRequest($request)
    {
        $optionsSet = curl_setopt_array($this->ch, [
            CURLOPT_URL => $this->url,
            CURLOPT_HEADER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CONNECTTIMEOUT => $this->timeout,
            CURLOPT_USERAGENT => 'JSON-RPC Random.org PHP Client',
            CURLOPT_HTTPHEADER => $this->headers,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_SSL_VERIFYPEER => $this->verifyPeer,
            CURLOPT_POSTFIELDS => json_encode($request)
        ]);

        if (!$optionsSet) {
            throw new \Exception('Cannot set curl options');
        }

        $responseBody = curl_exec($this->ch);
        $responseCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

        if (curl_errno($this->ch)) {
            throw new \RuntimeException(curl_error($this->ch));
        }

        if ($responseCode === 401 || $responseCode === 403) {
            throw new \RuntimeException('Access denied');
        }

        $response = json_decode($responseBody, true);

        if ($this->debug) {
            echo('==> Request: '.PHP_EOL.json_encode($request, JSON_PRETTY_PRINT));
            echo('==> Response: '.PHP_EOL.json_encode($response, JSON_PRETTY_PRINT));
        }

        return $response;
    }
public function makeRequest($request)
    {
        $optionsSet = curl_setopt_array($this->ch, [
            CURLOPT_URL => $this->url,
            CURLOPT_HEADER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CONNECTTIMEOUT => $this->timeout,
            CURLOPT_USERAGENT => 'JSON-RPC Random.org PHP Client',
            CURLOPT_HTTPHEADER => $this->headers,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_SSL_VERIFYPEER => $this->verifyPeer,
            CURLOPT_POSTFIELDS => json_encode($request)
        ]);

        if (!$optionsSet) {
            throw new \Exception('Cannot set curl options');
        }

        $responseBody = curl_exec($this->ch);
        $responseCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

        if (curl_errno($this->ch)) {
            throw new \RuntimeException(curl_error($this->ch));
        }

        if ($responseCode === 401 || $responseCode === 403) {
            throw new \RuntimeException('Access denied');
        }

        $response = json_decode($responseBody, true);

        if ($this->debug) {
            echo('==> Request: '.PHP_EOL.json_encode($request, JSON_PRETTY_PRINT));
            echo('==> Response: '.PHP_EOL.json_encode($response, JSON_PRETTY_PRINT));
        }

        return $response;
    }
public function makeRequest ( $ request ) { $ optionsSet = curl_setopt_array ( $ this -> ch , [ CURLOPT_URL => $ this -> url , CURLOPT_HEADER => false , CURLOPT_RETURNTRANSFER => true , CURLOPT_CONNECTTIMEOUT => $ this -> timeout , CURLOPT_USERAGENT => 'JSON-RPC Random.org PHP Client' , CURLOPT_HTTPHEADER => $ this -> headers , CURLOPT_FOLLOWLOCATION => false , CURLOPT_CUSTOMREQUEST => 'POST' , CURLOPT_SSL_VERIFYPEER => $ this -> verifyPeer , CURLOPT_POSTFIELDS => json_encode ( $ request ) ] ) ; if ( ! $ optionsSet ) { throw new \ Exception ( 'Cannot set curl options' ) ; } $ responseBody = curl_exec ( $ this -> ch ) ; $ responseCode = curl_getinfo ( $ this -> ch , CURLINFO_HTTP_CODE ) ; if ( curl_errno ( $ this -> ch ) ) { throw new \ RuntimeException ( curl_error ( $ this -> ch ) ) ; } if ( $ responseCode === 401 || $ responseCode === 403 ) { throw new \ RuntimeException ( 'Access denied' ) ; } $ response = json_decode ( $ responseBody , true ) ; if ( $ this -> debug ) { echo ( '==> Request: ' . PHP_EOL . json_encode ( $ request , JSON_PRETTY_PRINT ) ) ; echo ( '==> Response: ' . PHP_EOL . json_encode ( $ response , JSON_PRETTY_PRINT ) ) ; } return $ response ; }
make the request to the server and get response

@param $request
@return mixed
@throws RuntimeException
@throws \Exception
make the request to the server and get response