session_set_save_handler Sets user-level session storage functions &reftitle.description; boolsession_set_save_handler callbackopen callbackclose callbackread callbackwrite callbackdestroy callbackgc boolsession_set_save_handler SessionHandlerInterfacesessionhandler boolregister_shutdowntrue session_set_save_handler sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database. &reftitle.parameters; This function has two prototypes. sessionhandler An instance of a class implementing SessionHandlerInterface, such as SessionHandler, to register as the session handler. register_shutdown Register session_register_shutdown as a register_shutdown_function function. or open Open function, this works like a constructor in classes and is executed when the session is being opened. The open function expects two parameters, where the first is the save path and the second is the session name. close Close function, this works like a destructor in classes and is executed when the session operation is done. read Read function must return string value always to make save handler work as expected. Return empty string if there is no data to read. Return values from other handlers are converted to boolean expression. &true; for success, &false; for failure. write Write function that is called when session data is to be saved. This function expects two parameters: an identifier and the data associated with it. The "write" handler is not executed until after the output stream is closed. Thus, output from debugging statements in the "write" handler will never be seen in the browser. If debugging output is necessary, it is suggested that the debug output be written to a file instead. destroy The destroy handler, this is executed when a session is destroyed with session_destroy and takes the session id as its only parameter. gc The garbage collector, this is executed when the session garbage collector is executed and takes the max session lifetime as its only parameter. &reftitle.returnvalues; &return.success; &reftitle.examples; <function>session_set_save_handler</function> example The following example provides file based session storage similar to the PHP sessions default save handler files. This example could easily be extended to cover database storage using your favorite PHP supported database engine. ]]> <function>session_set_save_handler</function> using <classname>SessionHandler</classname> ]]> &reftitle.notes; As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions. It is possible to call session_write_close from the destructor to solve this chicken and egg problem. Current working directory is changed with some SAPIs if session is closed in the script termination. It is possible to close the session earlier with session_write_close. &reftitle.changelog; &Version; &Description; 5.4.0 Added SessionHandlerInterface and SessionHandler for implementing session handlers. &reftitle.seealso; The session.save_handler configuration directive