Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Flush data periodically to avoid request timeouts
Browse files Browse the repository at this point in the history
Heroku times out after 30 seconds (perfectly reasonable) but sending
data from the server allows the connection to stay alive longer.
  • Loading branch information
bryanjswift committed Sep 4, 2012
1 parent 09cd810 commit 37230c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion maintenance/loadtweets.php
Expand Up @@ -78,6 +78,8 @@ function importTweets($p){
}

echo l("User ID: " . $uid . "\n");
ob_flush();
flush();

// Find total number of tweets
$total = totalTweets($p);
Expand All @@ -88,6 +90,8 @@ function importTweets($p){
if($sinceID){
echo l("Newest tweet I've got: <strong>" . $sinceID . "</strong>\n");
}
ob_flush();
flush();

$page = 1;

Expand All @@ -113,6 +117,8 @@ function importTweets($p){
if(!IS64BIT && $i == 0 && $maxID == $tweet->id_str){ unset($data[0]); continue; }
// List tweet
echo l("<li>" . $tweet->id_str . " " . $tweet->created_at . "</li>\n");
ob_flush();
flush();
// Create tweet element and add to list
$tweets[] = $twitterApi->transformTweet($tweet);
// Determine new max_id
Expand Down Expand Up @@ -157,6 +163,8 @@ function importTweets($p){

// Checking personal favorites -- scanning all
echo l("\n<strong>Syncing favourites...</strong>\n");
ob_flush();
flush();
// Resetting these
$favs = array(); $maxID = 0; $sinceID = 0; $page = 1;
do {
Expand All @@ -181,6 +189,8 @@ function importTweets($p){
echo l("</ul>");
}
echo l("<strong>" . count($favs) . "</strong> favorite own tweets so far\n");
ob_flush();
flush();
$page++;
} while(!empty($data));

Expand All @@ -206,4 +216,4 @@ function importTweets($p){
}
}

require "mfooter.php";
require "mfooter.php";

0 comments on commit 37230c7

Please sign in to comment.