287不是有效的cURL句柄资源

时间:2014-03-25 19:31:59

标签: php curl nginx

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

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

安装了Curl(运行" curl url"在CLI中工作正常),还安装了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在完成之前可能已经删除了句柄,我该如何测试呢?

2 个答案:

答案 0 :(得分:0)

我认为你应该使用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);

答案 1 :(得分:0)

在处理XML时,我使用is_resource

$response = curl_exec($ch);
if(is_resource($ch)){
    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $responseBody = substr($response, $header_size);
    curl_close($ch);
    return $responseBody;
}
else{
    return $response;
}