bowhead icon indicating copy to clipboard operation
bowhead copied to clipboard

curl_getinfo(): supplied resource is not a valid cURL handle resource

Open markbell2410 opened this issue 7 years ago • 3 comments

In OneBroker.php line 148:

curl_getinfo(): supplied resource is not a valid cURL handle resource

Has anyone else had this error?

markbell2410 avatar Jan 25 '18 20:01 markbell2410

1broker is migrating to a new service, you can't trade btc there now so I am really not wanting to update them and will leave that for ccxt to manage.

rxmg-joeldg avatar Jan 26 '18 17:01 rxmg-joeldg

I'm also seeing this error when running example_usage. Can anyone recommend a work-around?

Dream-in-Color avatar Jan 28 '18 22:01 Dream-in-Color

Code at the following location closes curl early. https://github.com/joeldg/bowhead/blob/2c23430263d7a88972f0ba2efd46904db584a21b/app/Util/older/OneBroker.php#L142

Fix should be like this Old code

$response = curl_exec($curl);
        if ($response === false) {
            $error   = curl_errno($curl);
            $message = curl_error($curl);
            curl_close($curl);
        }
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);
        if($statusCode != 200) {
            error_log('STATUS CODE', $statusCode . ' ' . $response);
        }
        $body = json_decode($response, 1);

        if ($body['error'] === true) {
            throw new \RuntimeException(
                sprintf('OneBroker API returned an error - %d: %s', $body['error_code'], $body['error_message'])
            );
        }
        
        return array( "statusCode" => $statusCode, "body" => $body);

New code

        $response = curl_exec($curl);
        $responseInfo = curl_getinfo($curl);
        curl_close($this->ch);

        // url not reachable
        if($responseInfo['http_code'] == 0 && $responseInfo['header_size'] == 0){
            return $responseInfo;
        }

        // json_decode gives null when not json
        if(null === $output = json_decode($response, true)){
            return $response;
        }

        return $output;

Webist avatar Feb 08 '19 15:02 Webist