Example #1
0
 public static function go()
 {
     ob_start();
     // Global buffer
     start_benchmark('global');
     // Determine URI string
     $path = str_ireplace("index.php", "", $_SERVER['PHP_SELF']);
     $uri = $_SERVER['REQUEST_URI'];
     if (stripos($uri, $path) === 0) {
         $uri = substr($uri, strlen($path));
     }
     $uri = explode("?", $uri);
     $uri = rawurldecode(reset($uri));
     use_library('text');
     // Load up text modification functions. We'll need them for translation.
     use_library('files');
     self::$segments = array_filter(explode("/", $uri));
     // Split string into segments
     parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $_GET);
     // Apache rewrite might mess up our GET parameters. Let's just parse them ourselves.
     // Get current site based on URL
     $site = current_site();
     // Redirect to HTTPS if needed
     if (Config::https() && !(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {
         redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     }
     set_error_handler('_error_handler');
     if ($site->live) {
         //ini_set('display_errors',1);error_reporting(-1);
         register_shutdown_function('_shutdown_handler');
         // Set up function that will catch any coding errors
     } else {
         ini_set('display_errors', 1);
         error_reporting(-1);
         header("X-Robots-Tag: noindex, nofollow", true);
         // Prevent google from indexing us while we're not live yet
     }
     // Show admin page if requested
     if (segment(0) == ADMINDIR && Config::admin_enabled()) {
         array_shift(self::$segments);
         self::load_page_files();
         // Load content pages
         require BASEPATH . 'admin/admin.php';
         return FW4_Admin::show();
         // Download file if requested
     } else {
         if (count(self::$segments) == 2 && self::segment(0) == '_download') {
             $file = where('id = %d', intval(self::segment(1)))->get_row('site/downloads');
             if ($file) {
                 force_download(FILESPATH . $file->filename, $file->orig_filename);
                 exit;
             } else {
                 return false;
             }
             // Determine which page to load
         } else {
             use_library('piwik');
             Piwik::track_page_view();
             register_shutdown_function(function () {
                 close_connection();
                 Piwik::process();
             });
             // Load requested global libraries
             foreach (Config::global_libraries() as $library) {
                 use_library($library);
             }
             $has_correct_language = self::determine_language();
             self::load_page_files();
             // Load content pages
             if (self::route(ROUTE_EARLY)) {
                 return true;
             }
             if (!$has_correct_language) {
                 self::language_redirect();
             }
             if (self::route(ROUTE_DEFAULT)) {
                 return true;
             }
             // If no segments are defined, apply default segments
             $orig_segments = self::$segments;
             if (!isset(self::$segments[0])) {
                 self::$segments[0] = "home";
             }
             if (!isset(self::$segments[1])) {
                 self::$segments[1] = "index";
             }
             if (self::route(ROUTE_DEFAULT)) {
                 return true;
             }
             // There's no appropriate content with or without applying rules. Let's see if there's anything in the postprocessing rules.
             self::$segments = $orig_segments;
             if (self::route(ROUTE_LATE)) {
                 return true;
             }
             // Absolutely nothing matches. No content exist for requested segments.
             return false;
         }
     }
 }
Example #2
0
<?php

require_once 'MyQueue.php';
define('BENCHMARK_DSN', 'mysql:host=127.0.0.1;dbname=test');
define('BENCHMARK_USER', 'root');
define('BENCHMARK_PASS', '');
define('BENCHMARK_QNAME', 'test_queue');
define('BENCHMARK_MSG_NUM', 1000);
start_benchmark();
function start_benchmark()
{
    $pdo = new PDO(BENCHMARK_DSN, BENCHMARK_USER, BENCHMARK_PASS);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $queue = new MyQueue($pdo, BENCHMARK_QNAME);
    setup_table($pdo, BENCHMARK_QNAME);
    $results = array();
    try {
        $results['push'] = benchmark_push($queue, BENCHMARK_MSG_NUM);
        $results['pop'] = benchmark_pop($queue, BENCHMARK_MSG_NUM);
    } catch (Exception $e) {
        drop_table($pdo, BENCHMARK_QNAME);
        throw $e;
    }
    show_results($results, BENCHMARK_MSG_NUM);
    drop_table($pdo, BENCHMARK_QNAME);
}
function setup_table($pdo, $qname)
{
    drop_table($pdo, $qname);
    $pdo->exec("\n    CREATE TABLE `{$qname}` (\n      `id`           BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n      `locked_until` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',\n      `data`         BLOB NOT NULL,\n      PRIMARY KEY  (`id`)\n    ) ENGINE=InnoDB;\n  ");
}