Kohana Controller Setup unexpectly slow
I am a fairly 开发者_JAVA技巧experienced PHP developer, who is new to kohana.
I have built a website with Kohana, but after I uploaded to my server, I found part "Controller Setup" is unusually slow, took over 12s, whilst other take less than 0.5s,
Kohana Loading 0.014 1 0.49MB
Environment Setup 0.004 1 0.05MB
System Initialization 0.007 1 0.14MB
Controller Setup 12.058 1 1.42MB
ReflectionClass >newInstance() 12.054 1 1.35MB
Controller Execution 0.036 1 0.25MB
Total Execution 12.117 1 2.30MB
By digging into Kohana core, I have found ReflectionClass >newInstance() is causing the problem
But am not sure where I should go from here. :(
Help please. Thank you
I have dug deeper into my own code, looks like its Session::instance() whos causing the problem. Session::instance() 12.032 1 1.03MB
Further to my problem tracking, I have changed session driver to cache, and cache to memcache. But not much improvement. So I opened session.php, found this.
/**
* Singleton instance of Session.
*/
public static function instance()
{
if (Session::$instance == NULL)
{
// Create a new instance
new Session;
}
return Session::$instance;
}
-> "new Session;"!!
I can't see any point of this. I looked other classes, where it is written as return new xxx;
Like it says in the DocBlock, the Session class is using a Singleton pattern. The Singleton pattern makes sure there is only one instance of a class at any given time. The code you show is not doing anything special. It's a standard implementation of the pattern. I highly doubt this is the culprit. If any, you'd have to look in Session::__construct
.
A better approach would be to use Xdebug to profile the application and to get a detailed listing of the execution flow. This will shed much more light on what is taking so long.
精彩评论