Esempio n. 1
0
<?php

require_once '../init.php';
global $beSocial;
if ($beSocial != true) {
    $redis->del("queueSocial");
    exit;
}
$queueSocial = new RedisQueue('queueSocial');
$timer = new Timer();
while ($timer->stop() < 59000) {
    $killID = $queueSocial->pop();
    if ($killID != null) {
        beSocial($killID);
    }
}
function beSocial($killID)
{
    global $beSocial, $mdb;
    if (!isset($beSocial)) {
        $beSocial = false;
    }
    if ($beSocial === false) {
        return;
    }
    if ($killID < 0) {
        return;
    }
    $ircMin = 10000000000.0;
    $twitMin = 10000000000.0;
    $kill = $mdb->findDoc('killmails', ['killID' => $killID]);
Esempio n. 2
0
<?php

require_once '../init.php';
global $redisQServer;
if ($redisQServer == null) {
    exit;
}
$queueRedisQ = new RedisQueue('queueRedisQ');
$timer = new Timer();
while ($timer->stop() <= 59000) {
    $killID = $queueRedisQ->pop();
    if ($killID == null) {
        continue;
    }
    $rawmail = $mdb->findDoc('rawmails', ['killID' => $killID]);
    $zkb = $mdb->findField('killmails', 'zkb', ['killID' => $killID]);
    $zkb['href'] = "https://public-crest.eveonline.com/killmails/{$killID}/" . $zkb['hash'] . '/';
    unset($rawmail['_id']);
    $package = ['killID' => $killID, 'killmail' => $rawmail, 'zkb' => $zkb];
    RedisQ\Action::queue($redisQServer, $redisQAuthUser, $redisQAuthPass, $package);
}
Esempio n. 3
0
<?php

require_once '../init.php';
if ($redis->get("tq:itemsPopulated") != true) {
    Util::out("Waiting for all items to be populated...");
    exit;
}
$timer = new Timer();
$crestmails = $mdb->getCollection('crestmails');
$killmails = $mdb->getCollection('killmails');
$queueInfo = new RedisQueue('queueInfo');
$queueProcess = new RedisQueue('queueProcess');
$storage = $mdb->getCollection('storage');
$counter = 0;
$timer = new Timer();
while ($timer->stop() < 59000) {
    $killID = $queueProcess->pop();
    if ($killID !== null) {
        $raw = $mdb->findDoc('rawmails', ['killID' => $killID]);
        $mail = $raw;
        $kill = array();
        $kill['killID'] = $killID;
        $crestmail = $crestmails->findOne(['killID' => $killID, 'processed' => true]);
        if ($crestmail == null) {
            continue;
        }
        $date = substr($mail['killTime'], 0, 10);
        $date = str_replace('.', '-', $date);
        $today = date('Y-m-d');
        $kill['dttm'] = new MongoDate(strtotime(str_replace('.', '-', $mail['killTime']) . ' UTC'));
        $system = $mdb->findDoc('information', ['type' => 'solarSystemID', 'id' => (int) $mail['solarSystem']['id']]);
Esempio n. 4
0
<?php

require_once '../init.php';
// Send the mails to eve-kill cuz we're nice like that
$queueShare = new RedisQueue('queueShare');
do {
    $killID = $queueShare->pop();
    if ($killID == null) {
        continue;
    }
    $hash = $mdb->findField('crestmails', 'hash', ['killID' => $killID, 'processed' => true]);
    Util::getData("https://beta.eve-kill.net/crestmail/{$killID}/{$hash}/", 0);
} while ($killID != null);
Esempio n. 5
0
<?php

require_once '../init.php';
global $baseAddr;
$crestmails = $mdb->getCollection('crestmails');
$rawmails = $mdb->getCollection('rawmails');
$queueProcess = new RedisQueue('queueProcess');
$queueShare = new RedisQueue('queueShare');
$killsLastHour = new RedisTtlCounter('killsLastHour');
$counter = 0;
$timer = new Timer();
while (!Util::exitNow() && $timer->stop() < 115000) {
    $unprocessed = $crestmails->find(array('processed' => false))->sort(['killID' => -1])->limit(10);
    if (!$unprocessed->hasNext()) {
        sleep(1);
    }
    foreach ($unprocessed as $crestmail) {
        if (Util::exitNow()) {
            break;
        }
        $id = $crestmail['killID'];
        $hash = $crestmail['hash'];
        if ($mdb->exists('killmails', ['killID' => $id])) {
            $crestmails->update($crestmail, array('$set' => array('processed' => true)));
            continue;
        }
        $killmail = CrestTools::fetch($id, $hash);
        if ($killmail == null || $killmail == '' || !isset($killmail['attackers'])) {
            if ($killmail == 403) {
                $mdb->remove('crestmails', $crestmail);
            } else {
Esempio n. 6
0
<?php

require_once '../init.php';
$date = date('Ymd');
$redisKey = "tq:topAllTime:{$date}";
$queueTopAlltime = new RedisQueue("queueTopAlltime");
if ($redis->get($redisKey) != true) {
    $queueTopAlltime->clear();
    $iter = $mdb->getCollection('statistics')->find([], ['months' => 0, 'groups' => 0, 'topAllTime' => 0]);
    while ($row = $iter->next()) {
        if ($row['type'] == 'characterID') {
            continue;
        }
        $allTimeSum = (int) @$row['allTimeSum'];
        $currentSum = (int) @$row['shipsDestroyed'];
        if ($currentSum == 0) {
            continue;
        }
        if ($currentSum == $allTimeSum) {
            continue;
        }
        if ($currentSum - $allTimeSum < $allTimeSum * 0.01) {
            continue;
        }
        $queueTopAlltime->push($row['_id']);
    }
}
$redis->setex($redisKey, 86400, true);
if ($redis->llen('queueStats') > 100) {
    exit;
}
Esempio n. 7
0
<?php

require_once '../init.php';
$queueInfo = new RedisQueue('queueInfo');
$queueSocial = new RedisQueue('queueSocial');
$queueStats = new RedisQueue('queueStats');
$killmails = $mdb->getCollection('killmails');
$rawmails = $mdb->getCollection('rawmails');
$information = $mdb->getCollection('information');
$statArray = ['characterID', 'corporationID', 'allianceID', 'factionID', 'shipTypeID', 'groupID'];
while (!Util::exitNow()) {
    $killID = $queueInfo->pop();
    if ($killID !== null) {
        updateInfo($killID);
        updateStatsQueue($killID);
        $queueSocial->push($killID);
    }
}
function updateStatsQueue($killID)
{
    global $killmails, $statArray, $queueStats;
    $kill = $killmails->findOne(['killID' => $killID]);
    $involved = $kill['involved'];
    $sequence = $kill['sequence'];
    // solar system
    addToStatsQueue('solarSystemID', $kill['system']['solarSystemID'], $sequence);
    addToStatsQueue('regionID', $kill['system']['regionID'], $sequence);
    foreach ($involved as $inv) {
        foreach ($statArray as $stat) {
            if (isset($inv[$stat])) {
                addToStatsQueue($stat, $inv[$stat], $sequence);
Esempio n. 8
0
<?php

require_once '../init.php';
$queueInfo = new RedisQueue('queueInfo');
$queueSocial = new RedisQueue('queueSocial');
$queueStats = new RedisQueue('queueStats');
$queueRedisQ = new RedisQueue('queueRedisQ');
$killmails = $mdb->getCollection('killmails');
$rawmails = $mdb->getCollection('rawmails');
$information = $mdb->getCollection('information');
$statArray = ['characterID', 'corporationID', 'allianceID', 'factionID', 'shipTypeID', 'groupID'];
while (!Util::exitNow()) {
    $killID = $queueInfo->pop();
    if ($killID !== null) {
        updateInfo($killID);
        updateStatsQueue($killID);
        $queueSocial->push($killID);
        $queueRedisQ->push($killID);
    }
}
function updateStatsQueue($killID)
{
    global $killmails, $statArray, $queueStats;
    $kill = $killmails->findOne(['killID' => $killID]);
    $involved = $kill['involved'];
    $sequence = $kill['sequence'];
    // solar system
    addToStatsQueue('solarSystemID', $kill['system']['solarSystemID'], $sequence);
    addToStatsQueue('regionID', $kill['system']['regionID'], $sequence);
    if (isset($kill['locationID'])) {
        addToStatsQueue('locationID', $kill['locationID'], $sequence);
Esempio n. 9
0
<?php

require_once '../init.php';
$agents = [];
$qServer = new RedisQueue('queueServer');
$timer = new Timer();
while ($timer->stop() <= 59000) {
    $row = $qServer->pop();
    if ($row === null) {
        exit;
    }
    $agent = strtolower(@$row['HTTP_USER_AGENT']);
    if (!isBot($agent)) {
        if (isset($row['REQUEST_URI'])) {
            $uri = $row['REQUEST_URI'];
            $key = "cache:{$uri}";
            if (Util::startsWith($uri, '/kill/') || $uri == '/') {
                if (!$redis->exists($key)) {
                    $contents = @file_get_contents("http://zkillboard.com{$uri}");
                    if ($contents != '') {
                        $redis->setex($key, 300, $contents);
                    }
                }
            }
        }
    }
}
function isBot($agent)
{
    if (strpos($agent, 'chrome') !== false) {
        return false;
Esempio n. 10
0
<?php

require_once '../init.php';
$timer = new Timer();
$children = [];
$inProgress = [];
$maxChildren = 10;
$maxTime = 295000;
$queueStats = new RedisQueue('queueStats');
do {
    if ($redis->llen("queueServer") > 100) {
        exit;
    }
    $row = $queueStats->pop();
    if ($row !== null) {
        $id = $row['id'];
        $type = $row['type'];
        calcStats($row);
    }
} while ($timer->stop() <= $maxTime);
$status = 0;
function calcStats($row)
{
    global $mdb, $debug;
    $type = $row['type'];
    $id = $row['id'];
    $newSequence = $row['sequence'];
    $key = ['type' => $type, 'id' => $id];
    $stats = $mdb->findDoc('statistics', $key);
    if ($stats === null) {
        $stats = [];
Esempio n. 11
0
$requests->add(uniqid());
$load = getLoad();
// Check if the user has autologin turned on
if ($load < 20 && !User::isLoggedIn()) {
    User::autoLogin();
}
if ($load >= 20) {
    $uri = @$_SERVER['REQUEST_URI'];
    if ($uri != '') {
        $contents = $redis->get("cache:{$uri}");
        if ($contents !== false) {
            echo $contents;
            exit;
        }
        $_SERVER['requestDttm'] = $mdb->now();
        $qServer = new RedisQueue('queueServer');
        $qServer->push($_SERVER);
    }
}
// Theme
if (User::isLoggedIn()) {
    $theme = UserConfig::get('theme');
}
$app->config(array('templates.path' => $baseDir . 'templates/'));
// Error handling
$app->error(function (\Exception $e) use($app) {
    include 'view/error.php';
});
// Load the routes - always keep at the bottom of the require list ;)
include 'routes.php';
// Load twig stuff
Esempio n. 12
0
<?php

require_once '../init.php';
global $baseAddr, $baseDir;
$crestmails = $mdb->getCollection('crestmails');
$rawmails = $mdb->getCollection('rawmails');
$queueProcess = new RedisQueue('queueProcess');
$queueShare = file_exists("{$baseDir}/work/queueShare.php") ? new RedisQueue('queueShare') : null;
$killsLastHour = new RedisTtlCounter('killsLastHour');
$counter = 0;
$timer = new Timer();
while ($timer->stop() < 59000) {
    $unprocessed = $crestmails->find(array('processed' => false))->sort(['killID' => -1])->limit(10);
    if (!$unprocessed->hasNext()) {
        sleep(1);
    }
    foreach ($unprocessed as $crestmail) {
        $id = $crestmail['killID'];
        $hash = $crestmail['hash'];
        if ($mdb->exists('killmails', ['killID' => $id])) {
            $crestmails->update($crestmail, array('$set' => array('processed' => true)));
            continue;
        }
        $killmail = CrestTools::fetch($id, $hash);
        if (is_integer($killmail)) {
            Util::out("{$id} {$killmail}");
        }
        // The following if statements used to be a switch statement, but for some reason it didn't always process correctly
        if ($killmail == 403) {
            $mdb->getCollection("crestmails")->remove(['_id' => $crestmail["_id"]]);
            continue;
Esempio n. 13
0
            return;
        }
        while ($n and $this->redis->llen($n)) {
            (yield $this->redis->lpop($n));
        }
        return null;
    }
    /*
     *      Creates a generator then gets every element from the queue one by one
     */
    function rq_get_data($name)
    {
        $item_generator = $this->rq_gen_pop($name . ':product_info');
        print_r($item_generator);
        foreach ($item_generator as $item) {
            echo $item;
        }
    }
    function send_info($info, $name)
    {
        $info = json_encode($info);
        $this->redis->rpush($name . ':product_info', info);
    }
    function close()
    {
        $redis->close();
    }
}
$r = new RedisQueue();
$r->connect();
$r->rq_get_data("http://le-narguile.com");
Esempio n. 14
0
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    $queues = RedisQueue::getAll();
    return View::make('index')->withQueues($queues);
});
Route::get('queue/{name}/{type}', function ($name, $type) {
    $items = RedisQueue::getItems($name, $type);
    $listType = RedisQueue::type("queues:{$name}:{$type}");
    // jobs are stored as json encoded, we will decode them to create our list
    $items = $items->map(function ($item, $index) use($listType) {
        $object = json_decode($item);
        $object->encoded = $item;
        $object->delete = $listType === 'list' ? $index : urlencode($item);
        return $object;
    });
    return View::make('queue')->with(['name' => $name, 'type' => $type, 'items' => $items]);
});
Route::get('queue/{name}/{type}/delete', function ($name, $type) {
    $value = Input::get('value');
    RedisQueue::remove("queues:{$name}:{$type}", $value);
    return Redirect::to("queue/{$name}/{$type}");
});
Route::group(array('prefix' => 'api'), function () {
    Route::get('queue', function () {
        $redisQueue = new RedisQueue();
        $queues = $redisQueue->getQueues();
        return Response::json($queues);
    });
});
Esempio n. 15
0
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/../src/RedisClient.php';
require_once __DIR__ . '/../src/RedisQueue.php';
// init
$queue = new RedisQueue(new RedisClient('tcp://127.0.0.1:6379', 0, null));
define('LIMIT', empty($argv[1]) ? 10 : $argv[1]);
define('RAND', empty($argv[2]) ? 1 : $argv[2]);
// add jobs
echo 'Loads some workers (' . LIMIT . ')...' . "\n";
$start = microtime(true);
$jobs = array();
for ($i = 0; $i < LIMIT; $i++) {
    $jobs[] = $queue->doSleep(rand(1, RAND), 'John' . $i);
}
echo '...done in ' . round(microtime(true) - $start, 3) . 'sec (wait them) :' . "\n";
$start = microtime(true);
$started = array();
while (!empty($jobs)) {
    foreach ($jobs as $i => $job) {
        /*if ( !isset($started[$i]) && $queue->getJobStatus($job) == RedisQueue::STATE_PROGRESS ) {
              echo 'Starting ' . $job . ' at ' .  round( microtime(true) - $start, 3) . 'sec' . "\n";
              $started[$i] = $job;
          } else*/
        if ($queue->getJobStatus($job) == RedisQueue::STATE_DONE) {
            //echo 'Job ' . $job . ' finished' . "\n";
            unset($jobs[$i]);
        }
        /* */
        usleep(1000);
    }
Esempio n. 16
0
<?php

require_once '../init.php';
global $queueSocial, $redisQAuthUser;
$queueInfo = new RedisQueue('queueInfo');
$queueSocial = $beSocial == true ? new RedisQueue('queueSocial') : null;
$queueStats = new RedisQueue('queueStats');
$queueRedisQ = $redisQAuthUser != null ? new RedisQueue('queueRedisQ') : null;
$killmails = $mdb->getCollection('killmails');
$rawmails = $mdb->getCollection('rawmails');
$information = $mdb->getCollection('information');
$statArray = ['characterID', 'corporationID', 'allianceID', 'factionID', 'shipTypeID', 'groupID'];
$timer = new Timer();
while ($timer->stop() < 59000) {
    $killID = $queueInfo->pop();
    if ($killID !== null) {
        updateInfo($killID);
        updateStatsQueue($killID);
        if ($queueSocial != null) {
            $queueSocial->push($killID);
        }
        if ($queueRedisQ != null) {
            $queueRedisQ->push($killID);
        }
    }
}
function updateStatsQueue($killID)
{
    global $killmails, $statArray, $queueStats;
    $kill = $killmails->findOne(['killID' => $killID]);
    $involved = $kill['involved'];