views:

211

answers:

1

I am a fairly 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;

A: 

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.

Gordon
Thank you Gordon, I have now traced the problem to be session_start(). Not sure if Xdebug will going to much detail inside session_start, I am going to try fiddle it a bit further. After all this problem never happens on my local machine. Must be related to hardware setup.
Darkerstar