我有一个PHP脚本是这样的:curl,如何使用file_get_contents?
<?php
$likes = 'https://graph.facebook.com/google';
$fb = file_get_contents($likes);
$fb_array=json_decode($fb,true);
$all_likes = $fb_array['likes'];
$english_format = number_format($all_likes);
?>
有时会发生什么是该URL失败,我得到这样的:
Warning: file_get_contents(https://graph.facebook.com/google) [function.file-get-contents]: failed to open stream: HTTP request failed! in /var/www/html/google/index.php on line 774
我想知道是否有针对的方式代码将优雅地降级,因为我的整个网站都被关闭了。
我在想如果有一个PHP或卷曲替代处理该错误。
有什么想法?
感谢
编辑: 我可以这样的:
<?php
$likes = 'https://graph.facebook.com/google';
if([email protected]_get_contents($likes)){
$english_format = 123;
} else {
$fb = file_get_contents($likes);
$fb_array=json_decode($fb,true);
$all_likes = $fb_array['likes'];
$english_format = number_format($all_likes);
}
?>
,但它仍然会减慢我的网站
你为什么使用错误抑制? – NullUserException