简体   繁体   中英

Session was already started

I am working on a project based on cakephp 3, which is moderately heavy in terms of php and mysql for processor and memory usage, but serves the exact same pages 99% of the times to the users.

So I've decided like to use a caching system like this one that I have developed a few years ago. It just saves a cached html file of the complete page, avoiding to do all the elaborations on each request. It's a dumb system, but it does its job pretty well.

The problem is, I need to access the session variables for a few checks. To do so I trigger session_start() in my caching system, and sometimes cakephp throws this error when the page is not already cached:

Session was already started

How can I avoid this error? Is there a way to close the session in my caching system, so that cakephp can eventually start a new one? I have tried with session_abort and session_register_shutdown() , but the didn't work and I'm not even sure this is the correct way to do what I need...

EDIT: The processing flow is: request -> caching system -> cakephp. Therefore my session_start() comes before the cakephp one and I'd prefere not to touch cakephp core files, that's why the other questions were not useful to me. I'd like to solve this problem in my caching system instead.

You could check the session has not already started before attempting to call session_start();

if(!isset($_SESSION)) {
   session_start();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM