我正在尝试处理结果,$data = curl_exec($ch);而不是在屏幕上打印它.为了达到我设定的选项CURLOPT_RETURNTRANSFER,以true这样的:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
Run Code Online (Sandbox Code Playgroud)
在我的本地服务器上,这按预期工作,但当我在服务器上将相同的文件放在网上时,它不起作用.
当我设置CURLOPT_RETURNTRANSFER到false它的工作原理.
我究竟做错了什么?
我们正在尝试调试服务器上的一些cURL错误,我希望看到STDERR日志.目前,我们所能看到的错误是"错误代码:7",我们无法连接到目标服务器.我们已经联系了主机并制定了特殊规则来打开我们需要的端口,我们甚至暂时忽略了证书.
不过,我们无法连接.我需要调试这个,但我看不到任何相关的信息.
我认为,提及"VERBOSE"和"STDERR"的路线是最重要的.没有任何内容写入$ curl_log.我究竟做错了什么?遵循手册逻辑,这应该是正确的......
<?php
$curl = curl_init();
$curl_log = fopen("curl.txt", 'w');
$url = "http://www.google.com";
curl_setopt_array($curl, array(
CURLOPT_URL => $url, // Our destination URL
CURLOPT_VERBOSE => 1, // Logs verbose output to STDERR
CURLOPT_STDERR => $curl_log, // Output STDERR log to file
CURLOPT_SSL_VERIFYPEER => 0, // Do not verify certificate
CURLOPT_FAILONERROR => 0, // true to fail silently for http requests > 400
CURLOPT_RETURNTRANSFER => 1 // Return data received from server
));
$output = fread($curl_log, 2048);
echo $output; …Run Code Online (Sandbox Code Playgroud)