Free Source Code – Twitter Database Server: Phirehose Library
Twitter Database Server
MySQL Database Schema
Most of the work of receiving tweets from the Twitter streaming API is done by the Phirehose library, which is installed with the 140dev Twitter framework. Phirehose is a separate open source project from the 140dev framework, and you can find its home here. Fenn Bailey, the author of Phirehose, was nice enough to allow me to include the current version of his code with the 140dev framework code to simplify installation.
The Twitter streaming API requires a continuous network connection, a type of programming that I am not experienced at, which is why I adopted the Phirehose library. You must connect to the Twitter API server, and maintain that connection permanently, with tweets being received in real-time. Phirehose does all the work of creating the connection, receiving the tweets, and reestablishing the connection if it fails. It also automatically updates the search keywords or user ids that are needed for collecting tweets.
There are two Phirehose files you will need for using the 140dev framework code: Phirehose.php and OAuthPhirehose.php. Both are available at this Github repository. As a convenience, I have included both files in the download zip for this framework, so you can use these included files.
To use Phirehose you create a PHP script that extends the Phirehose class with code that stores the tweets as they are received. This is done by get_tweets.php, which is run as a continuous background process.