Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mokraemer opened this issue Dec 18, 2021 · 2 comments
Closed

Comments

@mokraemer
Copy link

mokraemer commented Dec 18, 2021

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

@nikic
Copy link
Member

nikic commented Dec 19, 2021

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.

@mokraemer
Copy link
Author

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

@nikic nikic changed the title session_save_handler incomplete stack trace Provide more information if writing session with custom save handler fails Dec 19, 2021
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 10, 2022
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 10, 2022
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 10, 2022
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants