Support » Plugin: WP Redis » wp redis cli hangs

  • Resolved ddyok

    (@ddyok)


    Running wp redis cli hangs. Can’t figure out why. Though it seems that wp redis is runnning fine:

    $ wp redis info
    +——————-+———–+
    | Field | Value |
    +——————-+———–+
    | status | connected |
    | used_memory | 2.61M |
    | uptime | 0 days |
    | key_count | 254 |
    | instantaneous_ops | 63/sec |
    | lifetime_hitrate | 79.41% |
    | redis_host | 127.0.0.1 |
    | redis_port | 6379 |
    | redis_auth | |
    | redis_database | 0 |
    +——————-+———–+

    $ wp redis cli

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hey @ddyok,

    Were you able to track this down?

    WP Redis simply calls the equivalent of WP_CLI::launch(‘redis-cli’), which uses proc_open() under the hood.

    Notably, the wp redis info command uses PhpRedis to fetch the relevant data, not the Redis CLI interface.

    Here are a few questions that might help you debug further:

    • What happens when you call redis-cli directly (with the relevant connection details)?
    • If you use wp shell, what happens when you call WP_CLI::launch() with some other command?
    • What system and shell are you on?
    Thread Starter ddyok

    (@ddyok)

    Hey Daniel,

    >What happens when you call redis-cli

    That works fine. So this not a very urgent matter. Maybe just to figure out what’s going on.

    > wp shell, what happens when you call WP_CLI::launch()

    wp> WP_CLI::launch()
    PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_CLI::launch(), 0 passed in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(46) : eval()’d code on line 1 and at least 1 expected in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php:1029

    Wonder what this is about? Trying to find out. I don’t know if it’s related to you.

    > What system and shell are you on?

    Linux 4.15.0-88-generic #88-Ubuntu SMPx86_64 x86_64 x86_64 GNU/Linux

    with bash

    Thank you.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Thanks for the update, @ddyok.

    Given redis-cli works, and WP Redis simply calls WP-CLI functions, it seems like this issue is specific to WP-CLI and not WP Redis.

    wp> WP_CLI::launch()
    PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_CLI::launch(), 0 passed in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(46) : eval()’d code on line 1 and at least 1 expected in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php:1029

    Wonder what this is about? Trying to find out. I don’t know if it’s related to you.

    You’d need to pass a command as an argument to WP_CLI::launch(). Try WP_CLI::launch( 'echo "Hello World"' );

    Also, can you share wp --info ?

    @schlessera Have you seen WP_CLI::launch() hang in this manner before? Any ideas on how to debug further?

    Thread Starter ddyok

    (@ddyok)

    $ wp shell
    wp> WP_CLI::launch( ‘echo “Hello World”‘ );
    => int(0)
    wp> exit
    $ wp –info
    OS: Linux 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64
    Shell: /bin/bash
    PHP binary: /usr/bin/php7.2
    PHP version: 7.2.24-0ubuntu0.18.04.3
    php.ini used: /etc/php/7.2/cli/php.ini
    WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir: phar://wp-cli.phar/vendor
    WP_CLI phar path: /var/www/wordpress
    WP-CLI packages dir:
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version: 2.4.0

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Huh.

    Given that WP_CLI::launch( 'echo "Hello World"' ); works as expected, maybe it’s not WP-CLI after all.

    Can you add var_dump( $cmd ); after this line and then, separately, try to run the command that’s dumped? I wonder whether there’s some way the command is formed that’s causing an issue on your system.

    Thread Starter ddyok

    (@ddyok)

    Added var_dump( $cmd ); to cli.php (line 34, after $cmd =), and it still hangs.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    It didn’t print out the value of $cmd?

    Thread Starter ddyok

    (@ddyok)

    Nope, nothing was dumped.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Ok. Can you add var_dump() throughout that method to see where the execution hangs?

    I just tested on my system. What I’ve seen so far:

    wp redis cli hangs on my system as well
    – The command it tries to run on my system is redis-cli -h "'127.0.0.1'" -p "'6379'" -a "''" -n "0"
    – If I run that comand manually, I get the following output:

    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Could not connect to Redis at '127.0.0.1':0: nodename nor servname provided, or not known
    not connected>

    – This means Redis was not active on that site. So I used valet to enable Redis: valet redis enable => this one also hangs!

    Given the above, my assumption is that Redis changed its CLI behavior (whether intentionally or not) and it doesn’t work as expected anymore.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Thanks @schlessera!

    I’m embarrassed to admit… I guess I didn’t even test wp redis cli locally. As soon as I tried it (again?), I was able to reproduce the issue.

    In debugging it further, it seems like the behavior of WP_CLI\Utils\esc_cmd() and WP_CLI::launch() have both changed since wp redis cli was written.

    WP_CLI\Utils\esc_cmd( 'redis-cli -h "%s" -p "%s" -a "%s" -n "%d"' ), while somewhat incorrect, used to accommodate the double-quoting. I’ve removed the quotes and now it produces a singularly-quoted string as expected.

    WP_CLI::launch() used array( STDIN, STDOUT, STDERR ) as the default $descriptorspec unless $return_detailed = true was provided. It looks like I accidentally broke this in 2014. I’m not sure why wp redis cli did work in 2016 but, regardless, switching back to proc_open( $cmd, array( STDIN, STDOUT, STDERR ), $pipes ); does the trick.

    @ddyok I’ve just tagged WP Redis v0.8.3. Thanks for your help tracking this issue down!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘wp redis cli hangs’ is closed to new replies.