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

session_set_save_handler(): Cannot change save handler when headers already sent #41

Open
robbash opened this issue Mar 31, 2021 · 0 comments
Labels

Comments

@robbash
Copy link

robbash commented Mar 31, 2021

Hi,

we're using this module in a SilverStripe website, we also use symbiote/silverstripe-sqs-jobqueue which is executed through CLI. Recently, we upgraded from PHP 7.1 to PHP 7.4, and SS from 4.3 to 4.7, and found warnings being issued during the SQS worker execution. We discovered that since PHP 7.2, calling session_set_save_handler() will raise a warning if there already is output on the console. However, I don't think that registering sessions needs to happen during CLI execution at all.

Stacktrace:

E_WARNING: session_set_save_handler(): Cannot change save handler when headers already sent
in session_set_save_handler called at /path/to/site/vendor/aws/aws-sdk-php/src/DynamoDb/SessionHandler.php (93)
in Aws\DynamoDb\SessionHandler::register called at /path/to/site/vendor/silverstripe/dynamodb/code/Model/DynamoDbSession.php (118)
in SilverStripe\DynamoDb\Model\DynamoDbSession::register called at /path/to/site/vendor/silverstripe/dynamodb/_config.php (7)
in require_once called at /path/to/site/vendor/silverstripe/framework/src/Core/Manifest/Module.php (289)
in SilverStripe\Core\Manifest\requireFile called at /path/to/site/vendor/silverstripe/framework/src/Core/Manifest/Module.php (187)
in SilverStripe\Core\Manifest\Module::activate called at /path/to/site/vendor/silverstripe/framework/src/Core/Manifest/ModuleManifest.php (153)
in SilverStripe\Core\Manifest\ModuleManifest::activateConfig called at /path/to/site/vendor/silverstripe/framework/src/Core/CoreKernel.php (213)
in SilverStripe\Core\CoreKernel::bootConfigs called at /path/to/site/vendor/silverstripe/framework/src/Core/CoreKernel.php (197)
in SilverStripe\Core\CoreKernel::boot called at /path/to/site/vendor/silverstripe/framework/src/Control/HTTPApplication.php (135)
in SilverStripe\Control\HTTPApplication::SilverStripe\Control\{closure} called at /path/to/site/vendor/silverstripe/framework/src/Control/Middleware/HTTPMiddlewareAware.php (65)
in SilverStripe\Control\HTTPApplication::callMiddleware called at /path/to/site/vendor/silverstripe/framework/src/Control/HTTPApplication.php (137)
in SilverStripe\Control\HTTPApplication::execute called at /path/to/site/vendor/silverstripe/framework/src/Control/HTTPApplication.php (116)
in SilverStripe\Control\HTTPApplication::handle called at /path/to/site/vendor/symbiote/silverstripe-sqs-jobqueue/sqs-worker.php (76)
in{closure} called at /path/to/site/vendor/symbiote/silverstripe-sqs-jobqueue/sqs-worker.php (90)

To overcome this problem short-term, we created a patch that is wrapping a condition around the $dynamoSession initialisation/registration in silverstripe/silverstripe-dynamodb/_config.php checking whether it's a CLI call or not.

...
if (PHP_SAPI !== 'cli') {
    $dynamoSession = DynamoDbSession::get();
    ...
}

Maybe that's something you want to consider putting into code, or you might even have a more elegant fix for that?

Cheers
-Rob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants