问题
I have a problem working with
curl_getinfo
I have already checked the php.ini for curl extension and everything seems to be fine and inside phpinfo();, curl is enable so I know that It shouldn't have any problem.
This function runs fine in my web server. It is my local machine with XAMPP 1.7.7 that gives me a hard time. Could this be because of firwall settings of my laptop?
Please note that the jpg file exists inside the Amazon s3 URL and I have checked the Amazon URL on the browser and it shows the image...
/////////////////// Edited //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
here is my code which is a function or method inside a class:
public function pictureExistence($id){
$url = AMAZON_S3_URL . $id . '.jpg';
//var_dump($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
//var_dump($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//var_dump($code);
if($code == 200){
$status = true;
}else{
$status = false;
}
curl_close($ch);
return $status;
}
回答1:
Try the following code and check whether it's working for you. It has been tested to work fine on XAMPP 1.7.7 .
<?php
// Create a curl handle
$ch = curl_init('http://www.yahoo.com/');
// Execute
curl_exec($ch);
// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
// Close handle
curl_close($ch);
?>
回答2:
I know this is old but i think you have the same problem i have. The problem is the httpS requets. In some way it doesn't work in xampp for windows, i remove the S and it works fine for me
来源:https://stackoverflow.com/questions/9768098/xampp-1-7-7-in-windows-7-returns-nothing-using-curl