Skip to content

Commit

Permalink
updated phirehose lib to latest version (really, really, really need …
Browse files Browse the repository at this point in the history
…to fix dependency inclusion..)
  • Loading branch information
andyjy committed Apr 22, 2014
1 parent ba99461 commit b7bad99
Show file tree
Hide file tree
Showing 21 changed files with 2,249 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phirehose
4 changes: 4 additions & 0 deletions lib/phirehose_2014-04-23/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.project
*.un~
.cache
.cache/*
38 changes: 38 additions & 0 deletions lib/phirehose_2014-04-23/Changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
See: http://code.google.com/p/phirehose/

0.2.4 (2010-04-07)
------------------
- Fixed bug where filter predicates got "stuck" as blank/null (reported by Toby P)
- Fixed bug where hang could occur after reconnect to quiet streams (reported by Toby P)
- Cleaned up connect() state initialization to reliably reconnect


0.2.3 (2010-02-26)
------------------
- Implemented stream idle timeouts (reconnects if streams die)
- Implemented per-connection DNS lookups
- Fixed bug where you could get caught in reconnect loop if invalid filter predicates specified
- Added getLastErrorMsg() and getLastErrorNo() methods (to deal with above)
- Improved logging

0.2.2 (2010-02-10)
------------------
- Fixed @version tag
- Improved error logging
- Improved connection validity check
- Added ghetto-queue-consume example

0.2.1 (2010-01-19)
------------------
- Fixed UserAgent string
- Removed per-entry log prefixes and moved to common log() method
- Added "ghetto queue" example

0.2.0 (2010-01-14)
------------------
- Added changelog :)
- Added locations functionality for use with the Twitter Geotagging API

0.1.0 (2009-09-30)
------------------
- Initial public release
41 changes: 41 additions & 0 deletions lib/phirehose_2014-04-23/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Phirehose #
A PHP interface to the Twitter Streaming API (firehose, etc). This library makes it easy to connect to and consume the Twitter stream via the Streaming API.

See:
* https://github.com/fennb/phirehose/wiki/Introduction and
* http://dev.twitter.com/pages/streaming_api

## Goals ##
* Provide a simple interface to the Twitter Streaming API for PHP applications
* Comply to Streaming API recommendations for error handling, reconnection, etc
* Encourage well-behaved streaming API clients
* Operate independently of PHP extensions (ie: shared memory, PCNTL, etc)

## What this library does do ##
* Handles connection/authentication to the twitter streaming API
* Consumes the stream handing off each status to be enqueued by a method of your choice
* Handles graceful reconnection/back-off on connection and API errors
* Monitors/reports performance metrics and errors

## What this library doesn't do ##
* Decode/process tweets
* Provide any sort of queueing mechanism for asynchronous processing (though some examples are included)
* Provide any sort of inter-process communication
* Provide any non-streaming API functionality (ie: user profile info, search, etc)

## How To Use ##

See the example subdirectory for example usage. In each example file you will need to insert your own oauth token/secret, and the key/secret for the Twitter app you have created.

* filter-oauth.php shows how to follow certain keywords.
* sample.php shows how to get a small random sample of all public statuses.
* userstream-alternative.php shows how to get user streams. (All activity for one user.)
* sitestream.php shows to how to get site streams. (All activity for multiple users.)

Please see the wiki for [documentation](https://github.com/fennb/phirehose/wiki/Introduction).

If you have any additional questions, head over to the Phirehose Users group [http://groups.google.com/group/phirehose-users]

It's recommended that you join (or at least regularly check) this group if you're actively using Phirehose so I can let you know when I release new versions.

Additionally, if you'd like to contact me directly, I'm [@fennb](http://twitter.com/fennb) on twitter.
20 changes: 20 additions & 0 deletions lib/phirehose_2014-04-23/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "fennb/phirehose",
"description": "A PHP interface to the Twitter Streaming API.",
"keywords": ["phirehose", "php", "twitter", "streaming", "api"],
"type": "library",
"homepage": "https://github.com/fennb/phirehose",
"license": "GPL",
"authors": [
{
"name": "Fenn Bailey",
"homepage": "http://fennb.com/"
}
],
"require": {
"php": ">=5.2.0"
},
"autoload": {
"classmap": ["lib"]
}
}
41 changes: 41 additions & 0 deletions lib/phirehose_2014-04-23/example/filter-oauth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');

/**
* Example of using Phirehose to display a live filtered stream using track words
*/
class FilterTrackConsumer extends OauthPhirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->setTrack(array('morning', 'goodnight', 'hello', 'the'));
$sc->consume();
52 changes: 52 additions & 0 deletions lib/phirehose_2014-04-23/example/filter-reconfigure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');

/**
* Example of how to update filter predicates using Phirehose
*/
class DynamicTrackConsumer extends OauthPhirehose
{

/**
* Subclass specific attribs
*/
protected $myTrackWords = array('morning', 'goodnight', 'hello', 'the');

/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
// We won't actually do anything with statuses in this example, see updateFilterPredicates() for important stuff
}

/**
* In this example, we just set the track words to a random 2 words. In a real example, you'd want to check some sort
* of shared medium (ie: memcache, DB, filesystem) to determine if the filter has changed and set appropriately. The
* speed of this method will affect how quickly you can update filters.
*/
public function checkFilterPredicates()
{
// This is all that's required, Phirehose will detect the change and reconnect as soon as possible
$randWord1 = $this->myTrackWords[rand(0, 3)];
$randWord2 = $this->myTrackWords[rand(0, 3)];
$this->setTrack(array($randWord1, $randWord2));
}

}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new DynamicTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->consume();
44 changes: 44 additions & 0 deletions lib/phirehose_2014-04-23/example/filter-track-geo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');

/**
* Example of using Phirehose to display a live filtered stream using geo locations
*/
class FilterTrackConsumer extends OauthPhirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->setLocations(array(
array(-122.75, 36.8, -121.75, 37.8), // San Francisco
array(-74, 40, -73, 41), // New York
));
$sc->consume();
41 changes: 41 additions & 0 deletions lib/phirehose_2014-04-23/example/filter-track.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
require_once('../lib/Phirehose.php');
require_once('../lib/OauthPhirehose.php');

/**
* Example of using Phirehose to display a live filtered stream using track words
*/
class FilterTrackConsumer extends OauthPhirehose
{
/**
* Enqueue each status
*
* @param string $status
*/
public function enqueueStatus($status)
{
/*
* In this simple example, we will just display to STDOUT rather than enqueue.
* NOTE: You should NOT be processing tweets at this point in a real application, instead they should be being
* enqueued and processed asyncronously from the collection process.
*/
$data = json_decode($status, true);
if (is_array($data) && isset($data['user']['screen_name'])) {
print $data['user']['screen_name'] . ': ' . urldecode($data['text']) . "\n";
}
}
}

// The OAuth credentials you received when registering your app at Twitter
define("TWITTER_CONSUMER_KEY", "");
define("TWITTER_CONSUMER_SECRET", "");


// The OAuth data for the twitter account
define("OAUTH_TOKEN", "");
define("OAUTH_SECRET", "");

// Start streaming
$sc = new FilterTrackConsumer(OAUTH_TOKEN, OAUTH_SECRET, Phirehose::METHOD_FILTER);
$sc->setTrack(array('morning', 'goodnight', 'hello', 'the'));
$sc->consume();
Loading

0 comments on commit b7bad99

Please sign in to comment.