mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 20:20:53 +00:00
Merge pull request #385 from zachborboa/master
Include additional information in error message
This commit is contained in:
@@ -70,8 +70,7 @@ $curl->get('https://www.example.com/');
|
||||
|
||||
if ($curl->error) {
|
||||
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo $curl->response;
|
||||
}
|
||||
|
||||
@@ -149,7 +148,8 @@ $multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->success(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was successful.' . "\n";
|
||||
echo 'response: ' . $instance->response . "\n";
|
||||
echo 'response:' . "\n";
|
||||
var_dump($instance->response);
|
||||
});
|
||||
$multi_curl->error(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
|
||||
|
||||
+9
-1
@@ -204,6 +204,7 @@ class Curl
|
||||
$this->options = null;
|
||||
$this->jsonDecoder = null;
|
||||
$this->xmlDecoder = null;
|
||||
$this->defaultDecoder = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,11 +341,18 @@ class Curl
|
||||
$this->call($this->beforeSendFunction);
|
||||
$this->rawResponse = curl_exec($this->curl);
|
||||
$this->curlErrorCode = curl_errno($this->curl);
|
||||
$this->curlErrorMessage = curl_error($this->curl);
|
||||
} else {
|
||||
$this->rawResponse = curl_multi_getcontent($ch);
|
||||
$this->curlErrorMessage = curl_error($ch);
|
||||
}
|
||||
$this->curlErrorMessage = curl_error($this->curl);
|
||||
$this->curlError = !($this->curlErrorCode === 0);
|
||||
|
||||
// Include additional error code information in error message when possible.
|
||||
if ($this->curlError && function_exists('curl_strerror')) {
|
||||
$this->curlErrorMessage = curl_strerror($this->curlErrorCode) . ': ' . $this->curlErrorMessage;
|
||||
}
|
||||
|
||||
$this->httpStatusCode = $this->getInfo(CURLINFO_HTTP_CODE);
|
||||
$this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5));
|
||||
$this->error = $this->curlError || $this->httpError;
|
||||
|
||||
@@ -536,6 +536,9 @@ class MultiCurl
|
||||
if ($info_array['msg'] === CURLMSG_DONE) {
|
||||
foreach ($this->curls as $key => $ch) {
|
||||
if ($ch->curl === $info_array['handle']) {
|
||||
// Set the error code for multi handles using the "result" key in the array returned by
|
||||
// curl_multi_info_read(). Using curl_errno() on a multi handle will incorrectly return 0
|
||||
// for errors.
|
||||
$ch->curlErrorCode = $info_array['result'];
|
||||
$ch->exec($ch->curl);
|
||||
curl_multi_remove_handle($this->multiCurl, $ch->curl);
|
||||
|
||||
Reference in New Issue
Block a user