Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Passing null as port into connect() doesn't set default port #1620

@Vidalia

Description

@Vidalia

We recently noticed an issue on our servers caused by an upgrade from php-redis 4.3.0 to 5.0.2. Previously we were passing null as the port number to connect() which would result in the default Redis port being used, but since 5.0.2 we've noticed that this behaviour has changed unexpectedly.

This problem is briefly mentioned in #1602 : passing null now appears to trigger the extension to try and connect to a socket, displaying the exception No such file or directory which seemed fairly nonsensical when it appeared to us that we were connecting to a network location.

Expected behaviour

Either

  1. Passing null as the second argument (port number) to connect() should automatically use the default port (6379), as it did in version <=4.3.0
  2. Exception message should be clarified (e.g. Failed to connect to socket: {socket path}: No such file or directory)

Actual behaviour

Pasing null as the port number fails with the message No such file or directory.

I'm seeing this behaviour on

Steps to reproduce, backtrace or example script

#!/usr/bin/php
<?php
try {
        $redis = new Redis();
        if($redis->connect("127.0.0.1", null)) {
                print("null ok\n");
        }

        if($redis->connect("127.0.0.1")) {
                print("omit ok\n");
        }

} catch (Exception $e) {
        print($e->getMessage() . "\n");
}

?>

Install 4.3.0 from pecl (pecl install redis-4.3.0) and run the above script
Uninstall 4.3.0, then install any 5.0.x from pecl (pecl install redis-5.0.x) and run the above script.

I've checked

  • There is no similar issue from other users
  • Issue isn't fixed in develop branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions