Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to use the Twitter API via PHP?

Tags:

php

twitter

api

A client would like me to add their Twitter stream to their website homepage, using a custom solution built in PHP.

The Twitter API obviously has a limited number of calls you can make to it per hour, so I can't automatically ping Twitter every time someone refreshes my client's homepage.

The client's website is purely HTML at the moment and so there is no database available. My solution must therefore only require PHP and the local file system (e.g. saving a local XML file with some data in it).

So, given this limited criteria, what's the best way for me to access the Twitter API - via PHP - without hitting my API call limit within a few minutes?

like image 835
markedup Avatar asked Jun 04 '09 11:06

markedup


1 Answers

It will be quite easy, once you can pull down a timeline and display it, to then add some file-based-caching to it.

check age of cache
Is it more than 5 mins old?
    fetch the latest information
    regenerate the HTML for output
    save the finished HTML to disk
display the cached pre-prepared HTML

PEAR's Cache_Lite will do all you need on the caching layer.

like image 126
Alister Bulman Avatar answered Nov 15 '22 00:11

Alister Bulman