Jump to:

22979 Posts in 11815 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Session::start() - Bug / Performance Improvement

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 880 Views
  • mightycoco
    Avatar
    Community Member
    3 Posts

    Session::start() - Bug / Performance Improvement Link to this post

    Hi there,

    I found that when doing large operations in the backend (like a batch action is converting a lot of images to create their thumbnails, etc) i can't browse Silverstripe anymore until the operation was finished.
    Interestingly i could open another browser and i was able to work in ss.

    I was playing around with PHP and HTTPD to make it multi-threading etc. to no avail.

    Today I found out that SS is starting every time you access the CSM (frontend + backend) a new PHP session
    sapphire/core/Session.php - Session::start()
    @session_start();

    The thing is, nowhere in ss the session is closed. No i tried to put a @session_write_close(); right after the session was started. The session information is written to the file and the session file on disk is no more locked.

    The question now: Is it REALLY safe, doing this? What could happen "if"... ?
    I haven't found negative side-effects until now. Browsing in the CMS seems to be much performant as well.

    Is this only a flaw in Silverstripe or was it done that way intentionally?

    Thanks,
    MC

    The whole function in session.php:

       public static function start($sid = null) {
          self::load_config();
          $path = self::get_cookie_path();
          $domain = self::get_cookie_domain();
          $secure = self::get_cookie_secure();

          if(!session_id() && !headers_sent()) {
             if($domain) {
                session_set_cookie_params(self::$timeout, $path, $domain, $secure /* secure */, true /* httponly */);
             } else {
                session_set_cookie_params(self::$timeout, $path, null, $secure /* secure */, true /* httponly */);
             }

             // @ is to supress win32 warnings/notices when session wasn't cleaned up properly
             // There's nothing we can do about this, because it's an operating system function!
             if($sid) session_id($sid);
             @session_start();
             @session_write_close(); // CHANGED: MCO - can we do this here ???
          }
       }

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Session::start() - Bug / Performance Improvement Link to this post

    But if you write the session to file at that stage what happens to the data when you set it using Session::set() further down the script? Perhaps you need to call the close in the inst_save() method in session - though you will still get the delay while everything loads as that will run after the response has been generated. The session unit tests may be of some use to help work out if there are any side effects.

    880 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.