We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

session already started warnings

Within my app I find that I am constantly seeing errors/warnings regarding sessions and I'm not sure why.

It's the standard "<b>Notice</b>: A session had already been started - ignoring session_start() in <b>app\config\services.php</b> on line <b>144</b><br />"

style message

and the session service is registered as follows

/**

  • Start the session the first time some component request the session service */ $di->set('session', function() {

    $session = new SessionAdapter(); $session->start();

    return $session; },true);

It's the same whether or not I set session to be shared (true) or not. The warning here is being generated when I use $this->security->getToken() in a view to generate csrf token but I've seen other instances usually happening when one of my views contains a call to content()

Does anyone know why this would be and how I can stop it from happening? Normally I'd use output buffering to suppress these errors but I'm not sure what's going on here

thanks



12.2k
Accepted
answer

Never mind I worked it out. The issue is that I've implemented the Facebook SDK. This makes a call to session_start() if it doesn't already exist and I was calling this before my session has been set-up. I've amended my code to now take this into account and actually make sure my session is started before I instantiate my Facebook object