My custom session handler (Oracle) causes PHP to seg fault

I have an Oracle session handler that triggers a seg fault on every page hit. I am using error_log to see it's progress. With brand new sessions, it is able to read and write before seg faulting. On existing sessions, it seg faults after read and never successfully writes.

Related tags: Oracle PHP

Turns out that my database handle was being destroyed before the write method was called.

I found out that PHP ends scripts by calling functions in the following order:

  1. functions registered with register_shutdown_function()
  2. object _destruct() functions
  3. session_write_close()

So the solution is to use register_shutdown_function().


I found out some other useful information about custom session handlers in PHP. session_start() triggers open() and read(). php shutdown (before objects are destroyed) triggers write(). session_destroy() triggers destroy(). gc() is called periodically according to session.gc_probability and session.gc_divisor. write(), destroy() and gc() functions should return true on success. read() should return a string.

Rating: 2

Propose a different solution...