Title: &#8220;Connection refused&#8221; while php can connect
Last modified: September 11, 2022

---

# “Connection refused” while php can connect

 *  Resolved [jeroendknl](https://wordpress.org/support/users/jeroendknl/)
 * (@jeroendknl)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/connection-refused-while-php-can-connect/)
 * Hi!
 * The plugin shows a connection refused, when i copy the connection code to a simple
   PHP file, the file can connect to redis…
 *     ```
       Status: Niet verbonden
       Client: PhpRedis (v5.3.2)
       Drop-in: Valid
       Disabled: No
       Ping: 
       Errors: [
           "Connection refused"
       ]
       PhpRedis: 5.3.2
       ```
   
 * Code copied from plugin to separate file which successfully connects:
 *     ```
       connect_using_phpredis($parameters);
        function connect_using_phpredis( $parameters ) {
          $version = phpversion( 'redis' );
          $redis = null;
   
              $redis = new Redis();
   
              $args = [
                  'host' => $parameters['host'],
                  'port' => $parameters['port'],
                  'timeout' => $parameters['timeout'],
                  '',
                  'retry_interval' => (int) $parameters['retry_interval'],
              ];
   
              if ( strcasecmp( 'tls', $parameters['scheme'] ) === 0 ) {
                  $args['host'] = sprintf(
                      '%s://%s',
                      $parameters['scheme'],
                      str_replace( 'tls://', '', $parameters['host'] )
                  );
              }
   
              if ( strcasecmp( 'unix', $parameters['scheme'] ) === 0 ) {
                  $args['host'] = $parameters['path'];
                  $args['port'] = -1;
              }
   
              if ( version_compare( $version, '3.1.3', '>=' ) ) {
                  $args['read_timeout'] = $parameters['read_timeout'];
              }
   
              call_user_func_array( [ $redis, 'connect' ], array_values( $args ) );
   
              if ( isset( $parameters['password'] ) ) {
                  $args['password'] = $parameters['password'];
                  $redis->auth( $parameters['password'] );
              }
   
              if ( isset( $parameters['database'] ) ) {
                  if ( ctype_digit( (string) $parameters['database'] ) ) {
                      $parameters['database'] = (int) $parameters['database'];
                  }
   
                  $args['database'] = $parameters['database'];
   
                  if ( $parameters['database'] ) {
                      $redis->select( $parameters['database'] );
                  }
              }
   
   
              var_dump($redis->ping('test'));
       }
       ```
   
 * `string(4) "test"`
    -  This topic was modified 3 years, 7 months ago by [jeroendknl](https://wordpress.org/support/users/jeroendknl/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Till Krüss](https://wordpress.org/support/users/tillkruess/)
 * (@tillkruess)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/connection-refused-while-php-can-connect/#post-16006125)
 * Odd. Can you move the `WP_REDIS_*` constant to the very top of your `wp-config.
   php`?
 *  Thread Starter [jeroendknl](https://wordpress.org/support/users/jeroendknl/)
 * (@jeroendknl)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/connection-refused-while-php-can-connect/#post-16010199)
 * that did the trick…. thank you!
 *  Thread Starter [jeroendknl](https://wordpress.org/support/users/jeroendknl/)
 * (@jeroendknl)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/connection-refused-while-php-can-connect/#post-16010202)
 * solved

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘“Connection refused” while php can connect’ is closed to new replies.

 * ![](https://ps.w.org/redis-cache/assets/icon-256x256.gif?rev=2568513)
 * [Redis Object Cache](https://wordpress.org/plugins/redis-cache/)
 * [Support Threads](https://wordpress.org/support/plugin/redis-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/redis-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redis-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redis-cache/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [jeroendknl](https://wordpress.org/support/users/jeroendknl/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/connection-refused-while-php-can-connect/#post-16010202)
 * Status: resolved