function tracker_run() { global $tweetQueue; $tweetQueue = new TweetQueue(); $tweetQueue->setoption('replace', false); if (defined('USE_INSERT_DELAYED') && USE_INSERT_DELAYED) { $tweetQueue->setoption('delayed', true); } if (defined('DISABLE_INSERT_IGNORE') && DISABLE_INSERT_IGNORE) { $tweetQueue->setoption('ignore', false); } else { $tweetQueue->setoption('ignore', true); } if (!defined("CAPTURE")) { /* logged to no file in particular, because we don't know which one. this should not happen. */ error_log("tracker_run() called without defining CAPTURE. have you set up config.php ?"); die; } $roles = unserialize(CAPTUREROLES); if (!in_array(CAPTURE, $roles)) { /* incorrect script execution, report back error to user */ error_log("tracker_run() role " . CAPTURE . " is not configured to run"); die; } // 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); }
if (!is_resource($thislockfp)) { logit("controller.log", "controller.php already running, skipping this check"); exit; } if (dbserver_has_utf8mb4_support() == false) { logit("controller.log", "DMI-TCAT requires at least MySQL version 5.5.3 - please upgrade your server"); exit; } $dbh = pdo_connect(); $roles = unserialize(CAPTUREROLES); // first gather all instructions sent by the webinterface to the controller (ie. the instruction queue) $commands = array(); foreach ($roles as $role) { $commands[$role] = array(); } if (array_key_exists('track', $commands) && geobinsActive() && geophp_sane()) { $geoActive = true; } else { $geoActive = false; } $rec = $dbh->prepare("SHOW TABLES LIKE 'tcat_controller_tasklist'"); if ($rec->execute() && $rec->rowCount() > 0) { $sql = "select task, instruction from tcat_controller_tasklist order by id asc lock in share mode"; foreach ($dbh->query($sql) as $row) { if ($geoActive && ($row['task'] = 'geotrack')) { $row['task'] = 'track'; } if (!array_key_exists($row['task'], $commands)) { continue; } $commands[$row['task']][] = $row;