POSTS
Using Twig with Phalcon PHP and kill it!!
Using Twig with Phalcon PHP.
Twig is a modern template engine for PHP.
Now we can Using Twig with Phalcon.
How to do:
1.Install Twing in library as git submodule.
git submodule add git@github.com:fabpot/Twig.git app/library/Twig
2.Install phalcon incubator in library as git submodule.
git submodule add git@github.com:phalcon/incubator.git app/library/incubator
3.Edit your app/config/loader.php file and add a twig,incubator to autoloader.
registerDirs(
array(
$config->application->controllersDir,
$config->application->modelsDir
)
);
$loader->registerNamespaces(array(
'Phalcon' => __DIR__ . '/../../app/library/incubator/Library/Phalcon/',
));
$loader->register();
require __DIR__ . '/../../app/library/Twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
4.Edit your app/config/services.php file and add a twig service to DI
/**
* Setting up the view component
*/
$di->set('twigService', function($view, $di) use ($config) {
$options = array(
'debug' => true,
'charset' => 'UTF-8',
'base_template_class' => 'Twig_Template',
'strict_variables' => false,
'autoescape' => false,
$config->application->cacheDir,
'auto_reload' => null,
'optimizations' => -1,
);
$twig = new \Phalcon\Mvc\View\Engine\Twig($view, $di, $options);
return $twig;
}, true);
$di->set('view', function () use ($config) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir($config->application->viewsDir);
$view->registerEngines(array(
".twig" => 'twigService'
));
return $view;
}, true);
- add New Twig templete Files app/views/index.twig.
Congratulations!
You're now flying with Phalcon. Great things are about to happen!
It work fine.[
]1
kill Phalcon!!
But it there good for Phalcon?
before:[
]2
after:[
]3
we can see it is slow down!
before : Total Incl. Wall Time (microsec): 1,339 microsecs
after : Total Incl. Wall Time (microsec): 20,496 microsecs
and it very different.
before:[
]4
after:[
]5
And i take off facebook XHPROF from index.php files.
handle()->getContent();
} catch (\Exception $e) {
echo $e->getMessage();
}
////end of facebook XHPROF
//$xhprof_data = xhprof_disable();
//$XHPROF_ROOT = __DIR__ . " /../../www/";
//include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
//include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
//
//$xhprof_runs = new XHProfRuns_Default();
//$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
//
//echo "http://localhost/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";
Using apache AB tools benchmark it.
before:[
]6
after:[
]7
it only “Requests per second: 311.85 [#/sec] (mean)” we lose 1000% speed.
Phalcon it is die.
I put all testing file on github https://github.com/SDpower/phalcon-pj1 .