Last active
November 1, 2022 02:36
-
-
Save levymetal/5083723 to your computer and use it in GitHub Desktop.
Stand-alone version of the php twitter cache found @ https://github.com/levymetal/php-twitter-cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting( 0 ); // don't let any php errors ruin the feed | |
$username = 'username'; | |
$number_tweets = 4; | |
$feed = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1&callback=?"; | |
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache'; | |
$modified = filemtime( $cache_file ); | |
$now = time(); | |
$interval = 600; // ten minutes | |
// check the cache file | |
if ( !$modified || ( ( $now - $modified ) > $interval ) ) { | |
$json = file_get_contents( $feed ); | |
if ( $json ) { | |
$cache_static = fopen( $cache_file, 'w' ); | |
fwrite( $cache_static, $json ); | |
fclose( $cache_static ); | |
} | |
} | |
header( 'Cache-Control: no-cache, must-revalidate' ); | |
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); | |
header( 'Content-type: application/json' ); | |
$json = file_get_contents( $cache_file ); | |
echo $json; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment