summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
authorNathan Gass2018-08-03 18:21:03 +0200
committerNathan Gass2018-08-03 18:21:03 +0200
commit8c399fb12571ae5950a1e3fe186e999abdc0b504 (patch)
treec481aa980c0775a4ccef0bc7ce9536297026eb5e /it_url.class
parent1228242e5272a26df3cabf3f79372f991c6dcb0f (diff)
downloaditools-8c399fb12571ae5950a1e3fe186e999abdc0b504.tar.gz
itools-8c399fb12571ae5950a1e3fe186e999abdc0b504.tar.bz2
itools-8c399fb12571ae5950a1e3fe186e999abdc0b504.zip
implement option verbose for verbose curl output
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class16
1 files changed, 14 insertions, 2 deletions
diff --git a/it_url.class b/it_url.class
index 15f2f2f..8542fff 100644
--- a/it_url.class
+++ b/it_url.class
@@ -226,6 +226,7 @@ static function curl_opts($p=array())
* @param $p['data'] POST data array with key-value pairs
* @param $p['files'] [fieldname => filename] of files to upload
* @param $p['method'] different HTTP method
+ * @param $p['verbose'] generate and capture curl verbose output in $this->verbose and alert mails
*/
function request($p=array())
@@ -237,6 +238,10 @@ function request($p=array())
$url->headers = array();
$p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p);
$opts = array(CURLOPT_HEADER => 1) + self::curl_opts($p + array('user' => $this->user, 'pass' => $this->pass, 'followlocation' => false));
+ if ($p['verbose']) {
+ $stderr = it::fopen("php://memory", "r+");
+ $opts += [CURLOPT_STDERR => $stderr, CURLOPT_VERBOSE => 1];
+ }
$curl = curl_init($url->url);
curl_setopt_array($curl, $opts);
@@ -265,8 +270,15 @@ function request($p=array())
$this->curlinfo = curl_getinfo($curl);
}
- if ($got === false && $p['retries'] <= 0)
- it::error((array)$p['it_error'] + ['title' => "problem getting $url->url with curl: (" . curl_errno($curl) . ") " . curl_error($curl), 'body' => curl_getinfo($curl)]);
+ if ($p['verbose']) {
+ rewind($stderr);
+ $this->verbose = stream_get_contents($stderr);
+ fclose($stderr);
+ }
+
+ if ($got === false && $p['retries'] <= 0) {
+ it::error((array)$p['it_error'] + ['title' => "problem getting $url->url with curl: (" . curl_errno($curl) . ") " . curl_error($curl), 'body' => curl_getinfo($curl) + ($p['verbose'] ? ['verbose' => $this->verbose] : [])]);
+ }
return $result;
}