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

RedisSession::start() Fatal Error #3

Open
jordm opened this issue Jun 5, 2023 · 1 comment
Open

RedisSession::start() Fatal Error #3

jordm opened this issue Jun 5, 2023 · 1 comment

Comments

@jordm
Copy link

jordm commented Jun 5, 2023

On PHP 8.1 I am getting issues connecting to redis through RedisSession

start-session.php:

// this must match the express-session `secret` in your Express app
define('EXPRESS_SECRET', 'test');

// this id mutator function helps ensure we look up
// the session using the right id
define('REDIS_SESSION_PREFIX', 'PHPREDIS_SESSION:');

...

require_once("redis-session-php/redis-session.php");

// Test PredisClient connection
$client = new Predis\Client([
	"scheme" => "tcp",
	"host" => "host.docker.internal",
	"port" => 6379,
	"password" => "test"
]);

$client->set("foo", "bar");

RedisSession::start([
	"scheme" => "tcp",
	"host" => "host.docker.internal",
	"port" => 6379,
	"password" => "test"
]);

$_SESSION["php"] = "Hello from PHP";
if (!isset($_SESSION["cookie"]))
  $_SESSION["cookie"] = array();

Looking at redis-cli, the output is:;

127.0.0.1:6379> keys *
1) "foo"

I'm getting the following error when running RedisSession::start():

php-dev    | NOTICE: PHP message: PHP Fatal error:  Uncaught TypeError: Session callback must have a return value of type bool, null returned in /var/www/php/src/redis-session-php/redis-session.php:47
php-dev    | Stack trace:
php-dev    | #0 /var/www/php/src/redis-session-php/redis-session.php(47): session_start()
php-dev    | #1 /var/www/php/src/start-session.php(55): RedisSession::start()
php-dev    | #2 /var/www/public/index.php(4): require_once('/var/www/php/sr...')
php-dev    | #3 {main}
php-dev    |   thrown in /var/www/php/src/redis-session-php/redis-session.php on line 47
@jordm jordm changed the title RedisSession::start() Exception RedisSession::start() Fatal Error Jun 5, 2023
@jordm
Copy link
Author

jordm commented Jun 5, 2023

Adding return true; to the open(), close(), and gc() methods solve this issue for PHP 8 forcing return types. But there is also an issue when passing null to json_decode now in the unserializer method

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

No branches or pull requests

1 participant