开发者

Zend throws "Session already started" exception, when I have not started a session, what gives?

Fatal error: Uncau开发者_开发问答ght exception 'Zend_Session_Exception' with message 'session has already been started by session.auto-start or session_start()' in /usr/include/ZendFramework-1.11.3/library/Zend/Session.php on line 462

It happens every reload. Things I have done:

  • Ensured that session.autostart=0 in my php.ini
  • searched my entire application for calls to session_start(), there are none
  • placed the following session configuration information in my config.ini:

    resources.session.save_path = APPLICATION_PATH "/../data/session"
    resources.session.use_only_cookies = true
    resources.session.remember_me_seconds = 864000
    
  • removed the above from my config.ini, didn't make a difference

  • restarted apache, several times
  • finally I only use Zend_Session_Namespace(), which is initialized in my controller's init() function.

I'm getting that error every time. What gives? What else haven't I checked? The only place the word "session" even exists in my Application (outside of the Zend library) is in this one controller:

<?php

class ContributeController extends Zend_Controller_Action
{
    private $_session;

    private function getSession() {
        return $this->_session;
    }

    public function init()
    {
        $this->_session = new Zend_Session_Namespace('contribute');
    }

    public function indexAction()
    {
        // action body
    }

    public function addAction() {
        $this->getSession()->form = new Application_Form_Contribute_Add_Main();
        $this->view->form = $this->getSession()->form;
    }

    public function importAction() {}


}

?>

Here's a grep search of my php.ini for ^session:

session.save_handler = files
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly = 
session.serialize_handler = php
session.gc_divisor     = 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = 1
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 4

session.auto_start, clearly off.

Why am I getting this error every time? What is going on here?

Edit For the moment it seems this was caused by attempting to store too much in the session when I attempted to store that form. When I rewrote my code to store a very simple array outlining the form's structure instead, the error went away and hasn't returned. I may return to this if it reappears and I'm not confident that it won't yet.


Check that the session data folder defined in your application.ini exists and is writable : when it is not the case, the same exception is thrown with this bogus message.


The only thing I can think of that you may have overlooked, would be this call somewhere in your application (bootstrap, perhaps?):

Zend_Session::start();


Okay, how about dump a debug_trace() into a file within the Zend_Session_Namespace constructor and see what you get per request. This should at least show you that the cause is outside of Zend or that indeed there are two close calls and especially where they are coming from.

I somehow think you are reloading your form page internally causing the init() controller to run twice. Starting the session earlier like karim79 suggested in the bootstrap should cure such cases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜