php - curl 窗口 : the provided file handle is not writable

标签 php windows curl

我在执行 curl 请求时随机“无错误地挂起”。我正在尝试检测来源,因为 Web 服务器和 php 日志没有显示任何错误,所以我尝试启用 CURLOT_STDERR

我有以下代码:

$file = 'curl.txt';
$curl = curl_init();
$curl_log = fopen($file, 'rw');
var_export(is_writable($file));
$url = 'http://www.google.com';

curl_setopt_array($curl, array(
    CURLOPT_URL             => $url,
    CURLOPT_VERBOSE         => 1,
    CURLOPT_STDERR          => $curl_log,
    CURLOPT_RETURNTRANSFER  => 1
));

$response = curl_exec($curl);
rewind($curl_log);
$output= fread($curl_log, 2048);
echo '<pre>'. print_r($output, 1). '</pre>';
fclose($curl_log);

is_writable 返回 true,但 curl 执行因以下错误而终止:

curl_setopt_array(): the provided file handle is not writable

我在 Windows 机器上运行 PHP 7.0.15 Fast CGI。

CURL 用户似乎没有写入权限,但我可以使用其他 PHP 函数在该文件上写入。

最佳答案

非常感谢hanshenrik的帮助。

var_dump(fwrite($curl_log,'test')); 返回 0。

所以我将行 $curl_log = fopen($file, 'rw'); 更改为 $curl_log = fopen($file, 'a'); 和问题解决了。

关于php - curl 窗口 : the provided file handle is not writable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42009019/

相关文章:

php - Magento 安装路线图说明

windows - 如何在 Windows 中解析规范文件名?

linux - 每 5 分钟将 curl 输出重定向到动态文件名

php - RESTeasy 使用的带有 JSON 正文的 POST - HTTP 100

javascript - 反复管理相同的 Tokbox session

php - 在 apache envvars 中获取系统范围的环境变量是否安全?

c# - System.Timers.Timer timer1_Elapsed 未触发!帮助!

java - 带有cygwin noclassdefinition的Windows中的hadoop发现错误

c++ - CURL 和 ZLIB 编译

javascript - PHP 联系表单无法正确提交