I can't connect to redis using php
P粉465287592
2023-09-01 15:37:59
<p>I cannot connect to redis using php.
I set up an environment with docker and tried to connect redis from php using php and redis containers, but it failed. I get the following error. </p>
<pre class="brush:php;toolbar:false;">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=</pre>
<p>This is the php file that is executed in response to the error. </p>
<pre class="brush:php;toolbar:false;"><?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";
?></pre>
<p>Part of the php.ini file. </p>
<pre class="brush:php;toolbar:false;">[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</pre>
<p>If I'm missing any information needed to resolve this issue, please let me know. Thank you in advance. </p>
<p>Attachment:
I type ping and it returns pong.
I can connect to redis from the php container using redis-cli. In addition, here is the path to redis.so.
<code>~/usr/lib/php/20190902/redis.so</code>
Path to php.ini (the server used is apache2).
<code>~/etc/php/7.4/apache2/php.ini</code></p>
Check if radish is working as a team
redis-cli ping
Answerpingpong
Make sure your PHP configuration contains the correct settings for the Redis extension. Check whether the
php.ini
file specifies the correct path toredis.so
and other necessary configurations.I have adjusted the Php.ini file as follows.
before fixing
adjusted
Thanks.