示例#1
0
 function testApcCache()
 {
     ini_set('apc.enable_cli', 1);
     apc_store('test', 3);
     is(3, apc_fetch('test'));
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_'));
     is(Roller\Router::cache_type_apc, $router->cache);
     $router->add('/item/:id', function ($id) {
         return $id;
     });
     $r = $router->dispatch('/item/12');
     $code = apc_fetch('_router_testing_');
     ok($code);
     $routes = eval($code);
     ok($routes);
     ok($routes->routes);
     // make sure cache reload works
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_'));
     $r = $router->dispatch('/item/12');
     is('12', $r());
     apc_delete('_router_testing_');
 }
示例#2
0
文件: bench.php 项目: c9s/roller
<?php

if (extension_loaded('roller')) {
    echo "extension loaded\n";
}
require '../vendor/pear/Universal/ClassLoader/BasePathClassLoader.php';
$loader = new \Universal\ClassLoader\BasePathClassLoader(array('../src', '../vendor/pear', '/opt/local/lib/php'));
$loader->useIncludePath(true);
$loader->register();
echo "init router\n";
$router = new Roller\Router();
$router->add('/', function () {
    return 'Hello World, please request /=/test for RESTful resource handler demo.';
});
foreach (range(1, 1000) as $i) {
    $router->add('/foo' . $i, function () {
        return 'bar';
    });
}
$router->routes->compile();
// var_dump( $router->routes->routes );
echo "dispatching\n";
$b = new SimpleBench();
$b->setN(10);
$b->iterate('roller_ext', 'roller_ext', function () use($router) {
    $r = roller_dispatch($router->routes->routes, '/foo1000');
});
$router->enableExtension = false;
$b->iterate('roller', 'roller', function () use($router) {
    $r = $router->dispatch('/foo1000');
});
示例#3
0
文件: RouterTest.php 项目: c9s/roller
 function testFileCache()
 {
     if (!file_exists('tests/cache')) {
         mkdir('tests/cache', 0755, true);
     }
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_', 'cache_dir' => 'tests/cache'));
     is(Roller\Router::cache_type_file, $router->cache);
     $router->add('/item/:id', function ($id) {
         return $id;
     });
     $r = $router->dispatch('/item/12');
     ok($r);
     is('12', $r());
     ok(file_exists('tests/cache/_router_testing_'));
     // the cache should be reloaded.
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_', 'cache_dir' => 'tests/cache'));
     $r = $router->dispatch('/item/12');
     ok($r);
     is('12', $r());
     unlink('tests/cache/_router_testing_');
 }