gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:47:16 34 4
gpt4 key购买 nike

我在执行 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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com