I can’t connect to redis with php.
I built an environment with docker and tried to connect to redis from php with a php and redis container, but it failed. I get the following error.
PHP Warning: PHP Startup: Unable to load dynamic library 'redis.so' (tried: /usr/lib/php/20190902/redis.so (/usr/lib/php/20190902/redis.so: undefined symbol: php_json_decode_ex), /usr/lib/php/20190902/redis.so.so (/usr/lib/php/20190902/redis.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Notice: session_start(): Redis not available while creating session_id in /var/www/html/index.php on line 2
PHP Warning: session_start(): Failed to read session data: redis (path: tcp://localhost:6379) in /var/www/html/index.php on line 2
string(0) ""
save_handler=redis
save_path=tcp://localhost:6379
session_id=
This is the php file that was executed in response to the error.
<?php
session_start();
ini_set('session.cookie-domain', 'localhost');
var_dump(session_id());
echo "save_handler=" . ini_get("session.save_handler") . "n";
echo "save_path=" . ini_get("session.save_path") . "n";
echo "session_id=" . session_id() . "n";
$_SESSION['libname'] = "PhpRedis";
?>
Part of the php.ini file.
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
session.save_handler = redis
session.save_path = "tcp://localhost:6379"
;verifying redis extension module
extension = redis.so
; default redis timeout
redis.timeout = 5
Please let me know if I am missing any information necessary to resolve this issue. Thank you in advance.
p.s.
I typed ping and it returned pong.
I can connect to redis from the php container with redis-cli. Also, here is the path to redis.so.
~/usr/lib/php/20190902/redis.so
The path to php.ini (server used is apache2).
~/etc/php/7.4/apache2/php.ini
2
Answers
I have adjusted the Php.ini file as follows.
Before adjustment
After adjustment
thank you.
check if radish is working as a team
redis-cli ping
answer
pong
Make sure that your PHP configuration contains the correct settings for the Redis extension. Check if the
php.ini
file specifies the correct path toredis.so
and other necessary configurations.