public static function call()
 {
     # By default, this view is turned off in the urls.php file.
     # This view is for debugging TileMap performace only!
     set_time_limit(0);
     header("Content-Type: text/plain; charset=utf-8");
     $user_id = $_GET['u'];
     self::out("Yo. I'm {$user_id}.\n\n");
     while (true) {
         srand(floor(time() / 10));
         $mode2 = rand(0, 9) <= 7;
         if ($mode2) {
             $row = Db::select_row("\n                    select z, x, y\n                    from okapi_tile_status\n                    where status = 2 and z < 20\n                    order by rand()\n                    limit 1;\n                ");
             $z = $row['z'] + 1;
             $x = $row['x'] << 1;
             $y = $row['y'] << 1;
             $x += rand(0, 1);
             $y += rand(0, 1);
         } else {
             $z = rand(5, 21);
             $x = rand(0, (1 << $z) - 1);
             $y = rand(0, (1 << $z) - 1);
         }
         $tiles = array();
         for ($xx = $x; $xx < $x + 4; $xx++) {
             for ($yy = $y; $yy < $y + 4; $yy++) {
                 $tiles[] = array($xx, $yy);
             }
         }
         srand();
         shuffle($tiles);
         foreach ($tiles as $tile) {
             list($x, $y) = $tile;
             self::out("Loading " . str_pad("({$z}, {$x}, {$y})... ", 30));
             $time_started = microtime(true);
             try {
                 $response = OkapiServiceRunner::call('services/caches/map/tile', new OkapiInternalRequest(new OkapiInternalConsumer(), new OkapiInternalAccessToken($user_id), array('z' => "{$z}", 'x' => "{$x}", 'y' => "{$y}")));
                 $runtime = microtime(true) - $time_started;
                 $ds = floor($runtime * 100);
                 self::out(str_repeat("#", $ds) . " ");
                 $b = floor(strlen($response->get_body()) / 256);
                 self::out(str_repeat("@", $b) . "\n");
             } catch (Exception $e) {
                 self::out("\n\n" . OkapiExceptionHandler::get_exception_info($e));
                 die;
             }
         }
     }
 }
Example #2
0
 /**
  * Execute all scheduled cronjobs of given type, reschedule, and return
  * UNIX timestamp of the nearest scheduled event.
  */
 public static function run_jobs($type)
 {
     require_once $GLOBALS['rootpath'] . 'okapi/service_runner.php';
     # We don't want other cronjobs of the same time to run simultanously.
     $lock = OkapiLock::get('cronjobs-' . $type);
     $lock->acquire();
     $schedule = Cache::get("cron_schedule");
     if ($schedule == null) {
         $schedule = array();
     }
     foreach (self::get_enabled_cronjobs() as $cronjob) {
         $name = $cronjob->get_name();
         if (!isset($schedule[$name]) || $schedule[$name] <= time()) {
             if ($cronjob->get_type() != $type) {
                 $next_run = isset($schedule[$name]) ? $schedule[$name] : time() - 1;
             } else {
                 try {
                     $cronjob->execute();
                 } catch (Exception $e) {
                     Okapi::mail_admins("Cronjob error: " . $cronjob->get_name(), OkapiExceptionHandler::get_exception_info($e));
                 }
                 $next_run = $cronjob->get_next_scheduled_run(isset($schedule[$name]) ? $schedule[$name] : time());
             }
             $schedule[$name] = $next_run;
             Cache::set("cron_schedule", $schedule, 30 * 86400);
         }
     }
     # Remove "stale" schedule keys (those which are no longer declared).
     $fixed_schedule = array();
     foreach (self::get_enabled_cronjobs() as $cronjob) {
         $name = $cronjob->get_name();
         $fixed_schedule[$name] = $schedule[$name];
     }
     unset($schedule);
     # Return the nearest scheduled event time.
     $nearest = time() + 3600;
     foreach ($fixed_schedule as $name => $time) {
         if ($time < $nearest) {
             $nearest = $time;
         }
     }
     Cache::set("cron_schedule", $fixed_schedule, 30 * 86400);
     $lock->release();
     return $nearest;
 }
Example #3
0
 /**
  * Remove database passwords and other sensitive data from the given
  * message (which is usually a trace, var_dump or print_r output).
  */
 public static function removeSensitiveData($message)
 {
     # This method is initially defined in the OkapiExceptionHandler class,
     # so that it is accessible even before the Okapi class is initialized.
     return OkapiExceptionHandler::removeSensitiveData($message);
 }