开发者

How to prevent an execution timeout error message to appear?

开发者 https://www.devze.com 2023-03-17 11:51 出处:网络
I\'ve got a piece of PHP code retrieving my last tweet : $twitterrequest = \'http://api.twitter.com/1/statuses/user_timeline.json?user_id=\' . $user_id . \'&include_rts=true&count=\' . $tweet

I've got a piece of PHP code retrieving my last tweet :

$twitterrequest = 'http://api.twitter.com/1/statuses/user_timeline.json?user_id=' . $user_id . '&include_rts=true&count=' . $tweetsToDisplay; 
$twitterci = curl_init($twitterrequest); 
curl_setopt($twitterci, CURLOPT_RETURNTRANSFER, TRUE); 
$twitterinput = curl_exec($twitterci); 
curl_close($twitterci); 
return ($twitterinput); 

When my Internet connection is really busy I ocasionally get the following message :

Fatal erro开发者_运维百科r: Maximum execution time of 30 seconds exceeded in D:...\www...\wp-content\themes...\home_tweet.php on line 26

How to prevent that, simply displaying nothing rather than this ugly error message ?


It might be more elegant to limit the time curl waits for an answer:

curl_setopt($twitterci, CURLOPT_TIMEOUT, 10);

to give it 10 seconds. That way you also get an opportunity to handle the timeout condition in a user-friendly way.

If that's not what you are looking for, have a look at How do I suppress a specific error in php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号