Home  >  Q&A  >  body text

I can't connect to redis using php

<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>
P粉465287592P粉465287592435 days ago669

reply all(2)I'll reply

  • P粉116631591

    P粉1166315912023-09-02 13:24:21

    1. Check if radish is working as a teamredis-cli ping Answerpingpong

    2. Make sure your PHP configuration contains the correct settings for the Redis extension. Check whether the php.ini file specifies the correct path to redis.so and other necessary configurations.

    reply
    0
  • P粉920199761

    P粉9201997612023-09-02 12:09:25

    I have adjusted the Php.ini file as follows.
    before fixing

    session.save_path = "tcp://localhost:6379"

    adjusted

    session.save_path = "tcp://redis:6379"

    Thanks.

    reply
    0
  • Cancelreply