Example #1
0
 * ----------------------
 *  route /faq
 * ----------------------
 */
$app->get("/faq", function () use($app) {
    $app->setFAQActive();
    return $app['twig']->render('faq.html.twig');
})->bind('faq');
/**
 * ----------------------
 *  route /status
 * ----------------------
 */
$app->get("/status/", function () use($app) {
    ob_start();
    echo "there are [[ " . RequestSlotManager::getInstance()->getLength() . " ]] available slots right now \n";
    echo "there are [[ " . QueueHelper::getInstance()->getItemListingDBQueueManager()->getLength() . " ]] items in the item listings queue \n";
    $content = ob_get_clean();
    return $app['twig']->render('status.html.twig', array('dump' => $content));
})->bind('status');
/**
 * ----------------------
 *  route /admin/session
 * ----------------------
 */
$app->get("/admin/session", function (Request $request) use($app) {
    // workaround for now to set active menu item
    $app->setHomeActive();
    return $app['twig']->render('admin_session.html.twig', array('flash' => $request->get('flash')));
})->bind('admin_session');
/**
<?php

use GW2Spidy\NewQueue\RequestSlotManager;
require dirname(__FILE__) . '/../autoload.php';
RequestSlotManager::getInstance()->setup();
$count = getAppConfig("gw2spidy.request-slots.count");
$cooldown = getAppConfig("gw2spidy.request-slots.cooldown");
/**
 * 100 slots with 10 sec cooldown gives us :
 *     100 requests / 10 seconds = 10 requests / sec
 * this is excluding the time it takes to handle the slots
 */
$max = $count / $cooldown;
$maxH = $max * 60 * 60;
echo "set up slot manager (count={$count}, cooldown={$cooldown}, max-requests per seconds={$max} / per hour={$maxH})\n";
use GW2Spidy\NewQueue\ItemListingDBQueueManager;
use GW2Spidy\NewQueue\ItemListingDBQueueWorker;
define('METHOD_SEARCH_JSON', 'search.json');
define('METHOD_LISTINGS_JSON', 'listings.json');
require dirname(__FILE__) . '/../autoload.php';
function logg($msg)
{
    echo "[" . date("Y-m-d H:i:s") . "] " . $msg;
}
$con = Propel::getConnection();
$debug = in_array('--debug', $argv);
if ($debug || defined('SQL_LOG_MODE') && SQL_LOG_MODE) {
    $con->setLogLevel(\Propel::LOG_DEBUG);
    $con->useDebug(true);
}
$slotManager = RequestSlotManager::getInstance();
$queueManager = new ItemListingDBQueueManager();
$queueWorker = new ItemListingDBQueueWorker($queueManager);
/*
 * $run up to $max in 1 process, then exit so process gets revived
 *  this is to avoid any memory problems (propel keeps a lot of stuff in memory)
 */
$run = 0;
$max = 100;
while ($run < $max) {
    sleep(4);
    $slot = $slotManager->getAvailableSlot();
    if (!$slot) {
        $sleep = $slotManager->getSlotsPerSecond() * 2;
        logg("no slots, sleeping [{$sleep}] ... \n");
        usleep($sleep * 1000 * 1000);
<?php

/**
 * check if the request slots are still at their configured amount
 */
use GW2Spidy\NewQueue\RequestSlotManager;
require dirname(__FILE__) . '/../autoload.php';
RequestSlotManager::getInstance()->check();