php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #25954 user session write handler called even if session contains no data
Submitted: 2003-10-22 11:47 UTC Modified: 2004-08-07 18:55 UTC
From: support at spill dot nl Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.3 OS: RHL 8.0
Private report: No CVE-ID: None
 [2003-10-22 11:47 UTC] support at spill dot nl
Description:
------------
The documentation at php.net for session_set_save_handler() states the following note:

The write handler is not executed if the session contains no data; this applies even if empty session variables are registered. This differs to the default file-based session save handler, which creates empty session files. 

http://php.net/session_set_save_handler


The documentation at Zend.com contains a similar statement. However the most simple user session handler I can come up with reports the write function being called with absolutely no registered variables.

I think this is good behaviour as the user session handler should decide for itself what to do with empty data, but the documentation should be fixed if this is expected behaviour.


Reproduce code:
---------------
<?php

// bogus session handler
function open($save_path,$session_name)         { return(error_log("sess_open('".$save_path."','".$session_name."')",0)); }
function close()                                { return(error_log("sess_close()",0)); }
function read($id)                              { error_log("sess_read('".$id."')",0); return(""); }
function write($id,$sess_data)                  { return(error_log("sess_write('".$id."','".$sess_data."')",0)); }
function destroy($id)                           { return(error_log("sess_destroy('".$id."')",0)); }
function gc($maxlifetime)                       { return(error_log("sess_gc('".$maxlifetime."')",0)); }

// install session handler
session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");

// start a session
session_start();

?>


Expected result:
----------------
I would expect the following lines in my logfile:

[22-Oct-2003 17:44:22] sess_open('/bigdisk/tmp/php','PHPSESSID')
[22-Oct-2003 17:44:22] sess_read('dd2340d600efe2925b4d8007ae8fbbd2')
[22-Oct-2003 17:44:22] sess_close()


Actual result:
--------------
However I find:

[22-Oct-2003 17:44:22] sess_open('/bigdisk/tmp/php','PHPSESSID')
[22-Oct-2003 17:44:22] sess_read('dd2340d600efe2925b4d8007ae8fbbd2')
[22-Oct-2003 17:44:22] sess_write('dd2340d600efe2925b4d8007ae8fbbd2','')
[22-Oct-2003 17:44:22] sess_close()


The call to write() is unexpected as the documentation states it will not be called under these circumstances.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-07 18:55 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Verified in PHP 5.0.0, note removed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC