Skip to content

Provide more information if writing session with custom save handler fails #7787

Closed

Description

@mokraemer

Description

The following code:

<?php
class MySessionHandler implements SessionHandlerInterface, SessionUpdateTimestampHandlerInterface {
    public function write($sessID, $sessData, $lock = false): bool {
        if(...){
            return false;
        }

        if(...){
            return false;
        }
        return true;
    }

    public function updateTimestamp($sessID, $val){
        return false;
    }
}

$handler = new MySessionHandler();
session_set_save_handler($handler, true);
session_start();

Resulted in this output:

session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /var/lib/php)

But I expected this output instead:
Having this "fake" session handler, it is impossible to say where session write failed and find the cause. An installed error handler just reports
errorHandler::errorHandler called at [:]

PHP Version

php 8.0.14

Operating System

Mageia 8

Activity

  1. nikic commented on Dec 19, 2021

    @nikic
    Member

    What would the desired additional information be? The name of the user defined session handler class?

    Edit: If you are asking for PHP to somehow distinguish which of the "return false" in SessionHandler::write() resulted in the failure, this is plainly impossible. You'd have to throw a notice from the session handler yourself if you wanted to achieve that.

  2. mokraemer commented on Dec 19, 2021

    @mokraemer
    Author

    I think the class name and the function called (updateTimestamp or write) would help to see which of those two functions failed.

  3. changed the title [-]session_save_handler incomplete stack trace[/-] [+]Provide more information if writing session with custom save handler fails[/+] on Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions