Jump to content

Can you set a timeout for your script


Presto-X

Recommended Posts

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;
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.