예제 #1
0
if (php_sapi_name() != 'cli') {
    die('This script must be invoked from the command line.');
}
if (!defined('OPENFUEGO') && function_exists('pcntl_fork')) {
    $error_message = "\n" . 'Do not run this script directly. Run fetch.php to start.' . "\n\n";
    die($error_message);
}
require_once __DIR__ . '/init.php';
register_shutdown_function(function () {
    Logger::fatal(__NAMESPACE__ . " collector was terminated.");
});
$twitter = new TwitterHandle();
$twitter->get("account/verify_credentials", array("include_entities" => 0, "skip_status" => 1));
if ($twitter->http_code !== 200) {
    $error_message = "Cannot continue. Your Twitter credentials appear to be invalid. Error code {$twitter->http_code}";
    Logger::info($error_message);
    die($error_message);
}
unset($twitter_handle);
$authorities = unserialize(\OpenFuego\AUTHORITIES);
$universe = new Universe();
/** The next line is commented out by default.
 * Uncomment it to repopulate the universe on each fetch. */
// $universe->populate($authorities, 1);
$citizens = $universe->getCitizens(1);
if (!$citizens) {
    $universe->populate($authorities, 1);
    $citizens = $universe->getCitizens(1);
}
$citizens = array_slice($citizens, 0, TWITTER_PREDICATE_LIMIT);
// Start streaming/collecting
예제 #2
0
}
if (php_sapi_name() != 'cli') {
    die('This script must be invoked from the command line.');
}
require_once __DIR__ . '/init.php';
if (!function_exists('pcntl_fork')) {
    $error_message = "\n" . 'To start OpenFuego, run these commands:' . "\n\n" . "\tnohup " . \PHP_BINDIR . '/php ' . BASE_DIR . '/collect.php > /dev/null 2> /dev/null & echo $!' . "\n" . "\tnohup " . \PHP_BINDIR . '/php ' . BASE_DIR . '/consume.php > /dev/null 2> /dev/null & echo $!' . "\n\n";
    die($error_message);
}
// Ignore hangup signal (when user exits shell)
pcntl_signal(SIGHUP, SIG_IGN);
// Handle shutdown tasks
pcntl_signal(SIGTERM, function () {
    global $_should_stop;
    $_should_stop = TRUE;
    Logger::info("Received shutdown request, finishing up.");
    return;
});
$pids = array();
$pids[0] = pcntl_fork();
if (!$pids[0]) {
    include_once __DIR__ . '/collect.php';
}
$pids[1] = pcntl_fork();
if (!$pids[1]) {
    include_once __DIR__ . '/consume.php';
}
echo __NAMESPACE__ . ' collector running as PID ' . $pids[0] . "\n";
echo __NAMESPACE__ . ' consumer running as PID ' . $pids[1] . "\n";
@file_put_contents(\OpenFuego\TMP_DIR . '/OpenFuego-collect.pid', $pids[0]);
@file_put_contents(\OpenFuego\TMP_DIR . '/OpenFuego-consume.pid', $pids[1]);