php - 287 不是有效的 cURL 句柄资源

标签 php curl nginx

最近使用 PHP5-FPM 将服务器从 Apache2 切换到 nginx/1.4.6,每次我尝试运行 curl 我得到:

curl_error(): 287 is not a valid cURL handle resource

安装了 Curl(在 CLI 中运行“curl url”可以正常工作),还安装了 PHP 模块。

我的代码:

$file_name_with_full_path = $composed_filename;
$post = array('image'=>'@'.$file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$result = curl_exec ($ch);
curl_close ($ch);

我四处搜索并找到了几个答案,但没有一个有效。发现一个说 cURL 可能在它完成之前删除了句柄,我该如何测试它?

最佳答案

我认为你应该使用 curl_file_create功能。试试这个

$file = curl_file_create('fullpath/to/image.jpg','image/jpeg','the_image');
$data = array('the_image' => $file);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

关于php - 287 不是有效的 cURL 句柄资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22644543/

相关文章:

linux - 在 Ubuntu 中重启 Nginx

php - 如何将图片与文章 ID 关联起来

php - 在 Android 中使用 Retrofit2 库上传文件

Php MySql While 循环如果有结果?

r - HTTP/2 帧层流错误 : bigrquery commands error in R studio but not in Base R

mysql - 无法连接到docker容器中的MySQL数据库

php - 使用 nginx 在 ubuntu 16、php 7 中显示 php 文件的白屏

php - 浏览 phpMyAdmin fatal error : Failed opening Message. class.php

jquery - 将curl命令转换为jQuery $.ajax()

php - 如何在 CURL 重定向上传递 cookie?