2013-09-01 41 views
1

这是我的代码PHP中的Curl会抛出异常吗?

<?php 
$url = "http://i.imgur.com/qV39tsL.gif"; 
$ch = curl_init(); 
echo $ch; 
$timeout = 20; 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$content = curl_exec($ch); 
curl_close($ch); 
echo $content; 
?> 

在我的环境,我的访问速度互联网是一个有点慢,所以有时我无法从imgur下载一些GIF格式。

但什么困惑我的是,我经常得到一个错误如下:

**ERROR 500: Internal Server Error.** 

我在计算器抬头,卷曲在PHP不应该让服务器停机。

那么有人会告诉我为什么我可以得到一个错误500:内部服务器错误?

谢谢~~~

回答

0

我已经执行脚本没有问题。 它可能是您的服务器上卷曲安装的东西。

检查服务器错误日志以查看更好的错误描述。 也许你需要重新安装卷曲。

0

试试这个(测试)有几个指令丢失。

不包括标题,只会显示.gif文件的二进制内容而不是图像本身。

<?php 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://i.imgur.com/qV39tsL.gif'); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); 
$content = curl_exec($ch); 
curl_close($ch); 
//Display the image in the browser 
header('Content-type: image/gif'); 
echo $content; 

/* You could also save the file to your server at the same time 
using the following outside this comment 
// save on server option 
$fh = fopen('filename.gif', 'w'); 
fwrite($fh, $content); 
fclose($fh); 
*/ 

?>