Question

I am storing quite a bit of data in my Zend Session namespaces and I'm wondering what's the most efficient way to reference it in my classes.

Currently my constructors set up access with lines such as $this->_storage = new Zend_Session_Namespace('products'); Later, when I need to access data in the namespace, I do so with $this->_storage->varname = $var; or $this->_storage->unsetAll();

Does this mean that there is disk activity every time I read or write to the session? Or is it read at the start of the request, and written at the end?

If there are multiple disk accesses within the duration of a single request, is there an easy way around it?

Was it helpful?

Solution

From the php man page on Session usage

Sessions follow a simple workflow. When a session is started, PHP will either retrieve an existing session using the ID passed (usually from a session cookie) or if no session is passed it will create a new session. PHP will populate the $_SESSION superglobal with any session data after the session has started. When PHP shuts down, it will automatically take the contents of the $_SESSION superglobal, serialize it, and send it for storage using the session save handler.

So, to answer your question, it means there's one read at session start, and one write at session shutdown, in between, the $_SESSION superglobal is essentially held in memory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top