bowhead
bowhead copied to clipboard
curl_getinfo(): supplied resource is not a valid cURL handle resource
In OneBroker.php line 148:
curl_getinfo(): supplied resource is not a valid cURL handle resource
Has anyone else had this error?
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.
I'm also seeing this error when running example_usage. Can anyone recommend a work-around?
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;