Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:35:34+00:00 2026-05-15T10:35:34+00:00

I’m working on a site with a simple php-generated twitter box with user timeline

  • 0

I’m working on a site with a simple php-generated twitter box with user timeline tweets pulled from the user_timeline rss feed, and cached to a local file to cut down on loads, and as backup for when twitter goes down. I based the caching on this: http://snipplr.com/view/8156/twitter-cache/. It all seemed to be working well yesterday, but today I discovered the cache file was blank. Deleting it then loading again generated a fresh file.

The code I’m using is below. I’ve edited it to try to get it to work with what I was already using to display the feed and probably messed something crucial up.

The changes I made are the following (and I strongly believe that any of these could be the cause):
– Revised the time difference code (the linked example seemed to use a custom function that wasn’t included in the code)

  • Removed the “serialize” function from the “fwrites”. This is purely because I couldn’t figure out how to unserialize once I loaded it in the display code. I truthfully don’t understand the role that serialize plays or how it works, so I’m sure I should have kept it in. If that’s the case I just need to understand where/how to deserialize in the second part of the code so that it can be parsed.

  • Removed the $rss variable in favor of just loading up the cache file in my original tweet display code.

So, here are the relevant parts of the code I used:

<?php
$feedURL = "http://twitter.com/statuses/user_timeline/#######.rss";

// START CACHING
$cache_file = dirname(__FILE__).'/cache/twitter_cache.rss';
    // Start with the cache 
if(file_exists($cache_file)){
 $mtime = (strtotime("now") - filemtime($cache_file));
 if($mtime > 600) {
  $cache_rss = file_get_contents('http://twitter.com/statuses/user_timeline/75168146.rss');
  $cache_static = fopen($cache_file, 'wb');
  fwrite($cache_static, $cache_rss);
  fclose($cache_static);  
 }
 echo "<!-- twitter cache generated ".date('Y-m-d h:i:s', filemtime($cache_file))." -->";
}
else {
 $cache_rss = file_get_contents('http://twitter.com/statuses/user_timeline/#######.rss');
 $cache_static = fopen($cache_file, 'wb');
 fwrite($cache_static, $cache_rss);
 fclose($cache_static);
}
//END CACHING

//START DISPLAY
   $doc = new DOMDocument();
 $doc->load($cache_file);
 $arrFeeds = array();
 foreach ($doc->getElementsByTagName('item') as $node) {
     $itemRSS = array ( 
         'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
         'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
         );
     array_push($arrFeeds, $itemRSS);
    }
 // the rest of the formatting and display code....
 }
?>

ETA 6/17 Nobody can help…?

I’m thinking it has something to do with writing a blank cache file over a good one when twitter is down, because otherwise I imagine that this should be happening every ten minutes when the cache file is overwritten again, but it doesn’t happen that frequently.

I made the following change to the part where it checks how old the file is to overwrite it:

 $cache_rss = file_get_contents('http://twitter.com/statuses/user_timeline/75168146.rss');
 if($mtime > 600 && $cache_rss != ''){
   $cache_static = fopen($cache_file, 'wb');
   fwrite($cache_static, $cache_rss);
   fclose($cache_static);  
 }

…so now, it will only write the file if it’s over ten minutes old and there’s actual content retrieved from the rss page. Do you think this will work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:35:35+00:00Added an answer on May 15, 2026 at 10:35 am

    Yes your code is problematic, because whatever Twitter sends you, you write it.
    You should test the file you get from Twitter like this:

    if (($mtime > 600) && ($cache_rss = file_get_contents($feedURL)))
    {
      file_put_contents($cache_rss);
    }
    

    file_get_contents() return false if there is an error, check it before caching some new content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 443k
  • Answers 443k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is using SELECT Max(ID) FROM table safer than using SELECT… May 15, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer I think this did it AddHandler Me.ParentForm.Move, AddressOf Popup_Move In… May 15, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer Globals.ThisAddIn.Application.AutoCorrect.DisplayAutoLayoutOptions = false just turns off the button for layout… May 15, 2026 at 6:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.