Search code examples
phpsessionerror-handlingkohanakohana-3

How to handle this "session failed to write file" error in PHP?


I am using the Kohana 3 framework, and am using the native session driver.

For some reason, occasionally the sessions fail to write to their file.

Warning: session_start() [function.session-start]: open(/tmp/sess_*****, O_RDWR) failed: Permission denied (13) in /home/site/public_html/system/classes/kohana/session/native.php  on line 27

I am pretty sure Kohana has its own in built error handler, but it is not triggered with this error (i.e. it shows up like a normal PHP error, not the Kohana error).

PHP error
(source: alexanderdickson.com)

Anyone that has ever used Kohana will notice this seems to have bypassed Kohana's error handling (perhaps set with set_error_handler()).

Is there anyway to stop this error from appearing without switching from the native session (i.e. file based) driver?

Should I just give good practice the boot and prepend an @ error suppressor to session_start() in the core code of Kohana? Should I relax the error_reporting()?

Thanks


Solution

  • You call ini_set('session.save_path', APPPATH.'sessions') (replace APPPATH.'sessions' with the directory you want) in bootstrap.php to force sessions to be written to application/sessions. This will increase the security of using native sessions and should solve your issue.