Welcome Guest, Not a member yet? Register   Sign In
CI 3 native session driver?
#1

I understand I have 4 choices right now: file, database, memcache and redis.

Is there a way to use native Php session so I could use the built in memcached extension and not have to use ci's memcache driver?

I understand all the drivers are just custom session handlers; but I am just surprised there is not a native session driver.
Reply
#2

The file driver is the native php session handler, which saves to files. It's just a wrapper for $_SESSION.

You can always just use $_SESSION in your application as well and not use any session library (that's about as native as you can get).
Reply
#3

(This post was last modified: 09-03-2015, 09:26 AM by blasto333.)

(09-03-2015, 09:18 AM)CroNiX Wrote: The file driver is the native php session handler, which saves to files. It's just a wrapper for $_SESSION.

You can always just use $_SESSION in your application as well and not use any session library (that's about as native as you can get).


It isn't really a wrapper because it uses its own file management. I want to use memcached extension which expects native php sessions. (Not managing their own files)
Reply
#4

So just use $_SESSION if you need pure native sessions?
Reply
#5

(09-03-2015, 09:39 AM)CroNiX Wrote: So just use $_SESSION if you need pure native sessions?

session_start() and session_name('cookie_name') need to be called every timeĀ and I want to use the CI helper methods as that is what my code uses now. In CI 2.x there was a native session 3rd party library I used; but with the new driver model there is not one that I know of that exists.
Reply
#6

AFAIK, there simply isn't anything that exists currently that uses pure native sessions in CI. So you can't do what you are wanting to do without using native $_SESSION. Just put the session_start and session_name in index.php, where it will be called for each request. The helpers you are using are most likely very simple things that you can create your own helper that works with native sessions to replace.
Reply
#7

What exactly do you need the memcached session driver to do which it doesn't already?

Memcached does the same thing CI3 does: it provides its own save handler for sessions. Both are equally "native" PHP sessions.
Reply
#8

(09-03-2015, 11:52 AM)mwhitney Wrote: What exactly do you need the memcached session driver to do which it doesn't already?

Memcached does the same thing CI3 does: it provides its own save handler for sessions. Both are equally "native" PHP sessions.

I already have that setup and it supports failover. If one memcached server goes down it can use the other one without losing session data. I couldn't seem to find this in CI's documentation besides providing weight values. With memcached you can write to more than one memcached server and when it fails it just starts using the ones that are available.
Reply
#9

(This post was last modified: 09-03-2015, 12:31 PM by mwhitney.)

If I'm reading the documentation of Memcached and the session driver code correctly, Memcached's failover support is handled by Memcached itself as long as you use the addServer() method, which CI's session driver does.

I suspect that the primary concern here would be that if, somehow, the host:port combination supplied to the sess_save_path config value was unavailable when the session was initially opened, you would not be able to access the session, even if other servers in the Memcached pool were available. However (again, if I'm reading the code correctly), I don't even believe that will be an issue, as it only appears to be checking whether the supplied host:port is in the existing list of servers in the Memcached instance and logs an error message if it fails to add the server. As long as the server list retrieved from Memcached is not empty, the open() method of the session handler returns true, so it should continue even if the host:port combination configured in sess_save_path is unavailable.

Also, regardless of which session handler you're using, there's never a guarantee that Memcached won't lose session data just because you're using server pools.
Reply
#10

Thank you for your input. I understand I can probably get one of these to work how I want to; but I don't see the harm in making a native session driver. I don't even think it would be too hard to write. This way you wouldn't have to deal with setting up file permissions (for the file driver; as long as php is setup correctly) AND it gives you the flexibility to use other session drivers that hook into php.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB