Presto-X Posted June 21, 2012 Share Posted June 21, 2012 Hey guys, I'm working on a script that pulls my latest tweet from twitter, the script seems to work really well, the only problem that I found, is when twitter is overloaded the script times out, but you have to wait like 30 sec. for the page to load to tell you that. Is there away to set a timeout of like 2-3 sec. then if its not done kick out a nice error message, or better yet read from a local cache file? Here is my current script: function getTwitterStatus($userid){ $url = 'https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=' . $userid . '&count=1'; $xml = simplexml_load_file($url) or die("could not connect"); foreach($xml->status as $status){ $tweet = array( 'created' => how_long_ago(strtotime($status->created_at)), 'text' => $status->text, 'username' => $status->user->screen_name); } return $tweet; } Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/ Share on other sites More sharing options...
Barand Posted June 21, 2012 Share Posted June 21, 2012 see set_time_limit() Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/#findComment-1355857 Share on other sites More sharing options...
The Little Guy Posted June 21, 2012 Share Posted June 21, 2012 you can do it via javascript. <div id="twitter_update_list"><!-- Your Latest Tweet Will Display Here Once Loaded --></div> <script type="text/javascript" src="//apis.jssnips.com/twitterblogger/latest.js"></script> <script type="text/javascript" src="//twitter.com/statuses/user_timeline/my_user_name.json?callback=twitterCallback2&count=1"></script> replace my_user_name with your twitter username Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/#findComment-1355860 Share on other sites More sharing options...
Presto-X Posted June 21, 2012 Author Share Posted June 21, 2012 Thanks for the replies, So with PHP would I do something like: function getTwitterStatus($userid){ set_time_limit(2); $url = 'https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=' . $userid . '&count=1'; $xml = simplexml_load_file($url) or die("could not connect"); foreach($xml->status as $status){ $tweet = array( 'created' => how_long_ago(strtotime($status->created_at)), 'text' => $status->text, 'username' => $status->user->screen_name); } return $tweet; } Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/#findComment-1355877 Share on other sites More sharing options...
The Little Guy Posted June 21, 2012 Share Posted June 21, 2012 If your going to do it via php, you should do it using curl, curl has built in timeout settings, if you do set_time_limit that will timeout YOUR webpage where as curl will only timeout the connection to twitter. Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/#findComment-1355890 Share on other sites More sharing options...
Presto-X Posted June 24, 2012 Author Share Posted June 24, 2012 Sweet thanks I will look in to CURL Quote Link to comment https://forums.phpfreaks.com/topic/264566-can-you-set-a-timeout-for-your-script/#findComment-1356521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.