本文整理汇总了PHP中tmhOAuth::streaming_request方法的典型用法代码示例。如果您正苦于以下问题:PHP tmhOAuth::streaming_request方法的具体用法?PHP tmhOAuth::streaming_request怎么用?PHP tmhOAuth::streaming_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmhOAuth
的用法示例。
在下文中一共展示了tmhOAuth::streaming_request方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tracker_run
//.........这里部分代码省略.........
}
// log execution environment
$phpstring = phpversion() . " in mode " . php_sapi_name() . " with extensions ";
$extensions = get_loaded_extensions();
$first = true;
foreach ($extensions as $ext) {
if ($first) {
$first = false;
} else {
$phpstring .= ',';
}
$phpstring .= "{$ext}";
}
$phpstring .= " (ini file: " . php_ini_loaded_file() . ")";
logit(CAPTURE . ".error.log", "running php version {$phpstring}");
// install the signal handler
if (function_exists('pcntl_signal')) {
// tick use required as of PHP 4.3.0
declare (ticks=1);
// See signal method discussion:
// http://darrendev.blogspot.nl/2010/11/php-53-ticks-pcntlsignal.html
logit(CAPTURE . ".error.log", "installing term signal handler for this script");
// setup signal handlers
pcntl_signal(SIGTERM, "capture_signal_handler_term");
} else {
logit(CAPTURE . ".error.log", "your php installation does not support signal handlers. graceful reload will not work");
}
// sanity check for geo bins functions
if (geophp_sane()) {
logit(CAPTURE . ".error.log", "geoPHP library is fully functional");
} elseif (geobinsActive()) {
logit(CAPTURE . ".error.log", "refusing to track until geobins are stopped or geo is functional");
exit(1);
} else {
logit(CAPTURE . ".error.log", "geoPHP functions are not yet available, see documentation for instructions");
}
global $ratelimit, $exceeding, $ex_start, $last_insert_id;
$ratelimit = 0;
// rate limit counter since start of script
$exceeding = 0;
// are we exceeding the rate limit currently?
$ex_start = 0;
// time at which rate limit started being exceeded
$last_insert_id = -1;
global $twitter_consumer_key, $twitter_consumer_secret, $twitter_user_token, $twitter_user_secret, $lastinsert;
$pid = getmypid();
logit(CAPTURE . ".error.log", "started script " . CAPTURE . " with pid {$pid}");
$lastinsert = time();
$procfilename = BASE_FILE . "proc/" . CAPTURE . ".procinfo";
if (file_put_contents($procfilename, $pid . "|" . time()) === FALSE) {
logit(CAPTURE . ".error.log", "cannot register capture script start time (file \"{$procfilename}\" is not WRITABLE. make sure the proc/ directory exists in your webroot and is writable by the cron user)");
die;
}
$networkpath = isset($GLOBALS["HOSTROLE"][CAPTURE]) ? $GLOBALS["HOSTROLE"][CAPTURE] : 'https://stream.twitter.com/';
// prepare queries
if (CAPTURE == "track") {
// check for geolocation bins
$locations = geobinsActive() ? getActiveLocationsImploded() : false;
// assemble query
$querylist = getActivePhrases();
if (empty($querylist) && !geobinsActive()) {
logit(CAPTURE . ".error.log", "empty query list, aborting!");
return;
}
$method = $networkpath . '1.1/statuses/filter.json';
$track = implode(",", $querylist);
$params = array();
if (geobinsActive()) {
$params['locations'] = $locations;
}
if (!empty($querylist)) {
$params['track'] = $track;
}
} elseif (CAPTURE == "follow") {
$querylist = getActiveUsers();
if (empty($querylist)) {
logit(CAPTURE . ".error.log", "empty query list, aborting!");
return;
}
$method = $networkpath . '1.1/statuses/filter.json';
$params = array("follow" => implode(",", $querylist));
} elseif (CAPTURE == "onepercent") {
$method = $networkpath . '1.1/statuses/sample.json';
$params = array('stall_warnings' => 'true');
}
logit(CAPTURE . ".error.log", "connecting to API socket");
$tmhOAuth = new tmhOAuth(array('consumer_key' => $twitter_consumer_key, 'consumer_secret' => $twitter_consumer_secret, 'token' => $twitter_user_token, 'secret' => $twitter_user_secret, 'host' => 'stream.twitter.com'));
$tmhOAuth->request_settings['headers']['Host'] = 'stream.twitter.com';
if (CAPTURE == "track" || CAPTURE == "follow") {
logit(CAPTURE . ".error.log", "connecting - query " . var_export($params, 1));
} elseif (CAPTURE == "onepercent") {
logit(CAPTURE . ".error.log", "connecting to sample stream");
}
$capturebucket = array();
$tmhOAuth->streaming_request('POST', $method, $params, 'tracker_streamCallback', array('Host' => 'stream.twitter.com'));
// output any response we get back AFTER the Stream has stopped -- or it errors
logit(CAPTURE . ".error.log", "stream stopped - error " . var_export($tmhOAuth, 1));
logit(CAPTURE . ".error.log", "processing buffer before exit");
processtweets($capturebucket);
}
示例2: my_streaming_callback
* secret into the place in this code marked with (YOUR_CONSUMER_KEY
* and YOUR_CONSUMER_SECRET)
* 3) From the application details page copy the access token and access token
* secret into the place in this code marked with (A_USER_TOKEN
* and A_USER_SECRET)
* 4) In a terminal or server type:
* php /path/to/here/streaming.php
* 5) To stop the Streaming API either press CTRL-C or, in the folder the
* script is running from type:
* touch STOP
*
* @author themattharris
*/
function my_streaming_callback($data, $length, $metrics)
{
// Twitter sends keep alive's in their streaming API.
// when this happens $data will appear empty.
// ref: https://dev.twitter.com/docs/streaming-apis/messages#Blank_lines
echo $data . PHP_EOL;
return file_exists(dirname(__FILE__) . '/STOP');
}
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET', 'user_token' => 'A_USER_TOKEN', 'user_secret' => 'A_USER_SECRET'));
$method = 'https://stream.twitter.com/1/statuses/filter.json';
// show Tweets which contan the word twitter OR have been geo-tagged within
// the bounding box -122.41,37.77,-122.40,37.78 OR are by themattharris
$params = array('track' => 'twitter', 'locations' => '-122.41,37.77,-122.40,37.78', 'follow' => '777925');
$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');
// output any response we get back AFTER the Stream has stopped -- or it errors
tmhUtilities::pr($tmhOAuth);
示例3: dirname
<?php
require dirname(__FILE__) . '/' . './lib/tmhOAuth/tmhOAuth.php';
require dirname(__FILE__) . '/' . './oauth.php';
require dirname(__FILE__) . '/' . './action.php';
$tmhOAuth = new tmhOAuth(array("consumer_key" => $consumer_key, "consumer_secret" => $consumer_secret, "user_token" => $user_token, "user_secret" => $user_secret));
//Tweet受信にfilter_callback関数を呼び出す
$method = "https://userstream.twitter.com/1.1/user.json";
$params = array();
$tmhOAuth->streaming_request('POST', $method, $params, 'filter_callback', true);
function filter_callback($data, $length, $metrics)
{
global $tmhOAuth;
@($res = json_decode($data));
//各アクションを実行 必要ないものはコメントアウトしましょ
/** えんくんのアレ **/
Action::Event_Watch($tmhOAuth, $res);
/** スクリーンネームとつぶやきを見る**/
Action::Tweet_Watch($tmhOAuth, $res);
/** らこらこらこ~w **/
Action::Lacolacolaco($tmhOAuth, $res, @$your_screen_name);
}
/***
* [メモ]エラー時のレスポンス
*
* [response][error] = connect() timed out!
* [response][errno] = 28
*/
/***
* 流れてくる情報は以下のURLを参照
*