对于我的大多数cron作业,我使用php /path/to/file.php > /dev/null
,如果有输出流到stderr
,我只能收到电子邮件。除了正在执行cURL请求之外,这适用于所有内容。
使用CURLOPT_RETURNTRANSFER = true
,如果我从浏览器运行该文件,它将不会输出,但是通过cron作业,我会收到一封包含连接尝试和已发送/已接收标头的请求详细信息。< / p>
有没有办法将此输出传输到stdout,或者最好将其从输出流中完全删除,因为如果我从浏览器运行它,我也不希望/需要查看此信息。< / p>
感谢您的时间。
代码:
getCURL("www.example.com", array(CURLOPT_COOKIEFILE => COOKIES));
function getCURL($url, $opt = array()){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "someuseragent");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIES);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt_array($ch, $opt);
$response_raw = curl_exec($ch);
$header = str_replace("\r\n\r\n", "", substr($response_raw, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE)));
foreach (explode("\r\n", $header) as $i => $line){
if ($i === 0){
$headers['http_code'] = $line;
} else {
list ($key, $value) = explode(': ', $line);
$headers[$key] = $value;
}
}
$body = substr($response_raw, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
curl_close($ch);
return array(
"header" => $headers,
"body" => $body,
"cookies" => COOKIES);
}
答案 0 :(得分:1)
您想将CURLOPT_VERBOSE
设置为false