• Resolved ellmann creative

    (@ellmanncreative)


    I’m using an external trigger for /path/to/my/website/wp-cron.php. This is managed by my webhost, and I have no clue as to how it works under the hood (though I suspect some implementation of a crontab, since I need to provide a filesystem path to the wp-cron.php file).

    The Object Cache plugin works OK in the website itself.

    However, when running via the trigger, I get:

    
    RedisException: Connection refused in /path/to/my/website/wp-content/object-cache.php:631
    Stack trace:
    #0 /path/to/my/website/wp-content/object-cache.php(631): Redis->connect('127.0.0.1', '6379', 1, NULL, NULL, 1)
    #1 /path/to/my/website/wp-content/object-cache.php(480): WP_Object_Cache->connect_using_phpredis(Array)
    #2 /path/to/my/website/wp-content/object-cache.php(173): WP_Object_Cache->__construct(true)
    #3 /path/to/my/website/wp-includes/load.php(701): wp_cache_init()
    #4 /path/to/my/website/wp-settings.php(131): wp_start_object_cache()
    ...
    

    I stress again: the plugin works when viewing the website directly.

    Please advise.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter ellmann creative

    (@ellmanncreative)

    As for the stack trace, I am unable to provide more of it. The messages I receive are clipped, and they don’t go into the website’s normal error log. I can confirm that the process does include my wp-config.php file (which has the required configuration parameters), but that’s all.

    I would suggest the REDIS cache perhaps should not be used during any wp-cron-related activities. Perhaps it can detect this and skip execution entirely?

    Thread Starter ellmann creative

    (@ellmanncreative)

    Do let us know if you address it, because we’re disabling the plugin for now (as it’s failing WP cron for us).

    Plugin Author Till Krüss

    (@tillkruess)

    It sounds like you’re executing the wp-cron.php via CLI or in a CLI process.

    Either your config isn’t loaded, or your CLI environment doesn’t have access to your Redis Server.

    Can you post your diagnostics here?

    Thread Starter ellmann creative

    (@ellmanncreative)

    How would I go about doing that? I mean, CLI execution has its own settings, does it not? I have no clue how to extract that information.

    Plugin Author Till Krüss

    (@tillkruess)

    First, I’d check wp redis status to see what your CLI is doing.

    Thread Starter ellmann creative

    (@ellmanncreative)

    Okay. It seems wp-cli doesn’t like the fact that I have wp-config.php actually reference the configuration somewhere else (there’s a require_once directive that points to the actual wp-config.php file). The error I’m getting is

    Error: Strange wp-config.php file: wp-settings.php is not loaded directly.

    Anything else I can try?

    Plugin Author Till Krüss

    (@tillkruess)

    Since you’re trying to debug your CLI enviroment object cache, not that I can think of. I’d suggest googling that error and resolve it first 👍

    Thread Starter ellmann creative

    (@ellmanncreative)

    I’ve managed to debug the wp-cli issue. Here’s the output of that command (note: I have sanitised the paths):

    $ php ~/wp-cli.phar redis status
    RedisException: Connection refused in /path/to/website/public-default/wp-content/object-cache.php:631
    Stack trace:
    #0 /path/to/website/public-default/wp-content/object-cache.php(631): Redis->connect('127.0.0.1', '6379', 1, NULL, NULL, 1)
    #1 /path/to/website/public-default/wp-content/object-cache.php(480): WP_Object_Cache->connect_using_phpredis(Array)
    #2 /path/to/website/public-default/wp-content/object-cache.php(173): WP_Object_Cache->__construct(true)
    #3 /path/to/website/public-default/wp-includes/load.php(701): wp_cache_init()
    #4 /path/to/website/public-default/wp-settings.php(131): wp_start_object_cache()
    #5 phar:///wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1271): require('/path/to...')
    #6 phar:///wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1192): WP_CLI\Runner->load_wordpress()
    #7 phar:///wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
    #8 phar:///wp-cli.phar/vendor/wp-cli/wp-cli/php/bootstrap.php(77): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
    #9 phar:///wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
    #10 phar:///wp-cli.phar/php/boot-phar.php(11): include('phar:///path/to...')
    #11 /wp-cli.phar(4): include('phar:///path/to...')
    #12 {main}
    Status: Not connected
    Client: PhpRedis (v5.2.2)
    Drop-in: Valid
    Disabled: No
    Ping:
    Connection Exception: Connection refused (RedisException)
    Errors: [
        "Connection refused"
    ]
    PhpRedis: 5.2.2
    Predis: Not loaded
    Credis: Not loaded
    PHP Version: 7.4.19
    Plugin Version: 2.0.18
    Redis Version: Unknown
    Multisite: No
    Filesystem: Working
    Global Prefix: "wp_"
    Blog Prefix: "wp_"
    WP_REDIS_HOST: "127.0.0.1"
    WP_REDIS_PORT: "6379"
    WP_REDIS_PASSWORD: ••••••••
    Global Groups: [
        "blog-details",
        "blog-id-cache",
        "blog-lookup",
        "global-posts",
        "networks",
        "rss",
        "sites",
        "site-details",
        "site-lookup",
        "site-options",
        "site-transient",
        "users",
        "useremail",
        "userlogins",
        "usermeta",
        "user_meta",
        "userslugs",
        "redis-cache"
    ]
    Ignored Groups: [
        "counts",
        "plugins",
        "themes",
        "blog-details",
        "blog-id-cache",
        "blog-lookup",
        "global-posts",
        "networks",
        "rss",
        "sites",
        "site-details",
        "site-lookup",
        "site-options",
        "site-transient",
        "users",
        "useremail",
        "userlogins",
        "usermeta",
        "user_meta",
        "userslugs",
        "redis-cache",
        "blog_meta",
        "wordfence",
        "wordfence-ls"
    ]
    Unflushable Groups: []
    Drop-ins: [
        "Redis Object Cache Drop-In v2.0.18 by Till Krüss"
    ]
    • This reply was modified 2 years, 11 months ago by ellmann creative.
    • This reply was modified 2 years, 11 months ago by Yui.
    Plugin Author Till Krüss

    (@tillkruess)

    Great work. It looks like your PHP cli process can’t connect to 127.0.0.1:6739

    Can you confirm that your web dashboard is showing the same connection?

    If so, the it might be a permissions issue that your hosting provider can help you resolve.

    Thread Starter ellmann creative

    (@ellmanncreative)

    I can confirm that my dashboard shows a connection to 127.0.0.1:6379, it says that it’s connected, and there’s a pretty graph (which I don’t understand) after a few moments.

    Plugin Author Till Krüss

    (@tillkruess)

    Try creating new php file:

    
    <?php
    
    $redis = new Redis;
    $redis->connect('127.0.0.1', 6379);
    $redis->auth('YOUR PASSWORD');
    
    var_dump($redis->ping());
    

    and then run php filename.php, what does it print?

    Thread Starter ellmann creative

    (@ellmanncreative)

    The output was empty, so I modified it:

    
    <?php
    
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    echo ">> Create object\n";
    $redis = new Redis;
    
    echo ">> Connect\n";
    $redis->connect('127.0.0.1', 6379);
    
    echo ">> Auth\n";
    $redis->auth( 'MY_PASSWORD' );
    
    echo ">> Ping\n";
    var_dump($redis->ping());
    
    echo ">> Complete\n";
    

    Output is:

    
    >> Create object
    >> Connect
    
    Fatal error: Uncaught RedisException: Connection refused in /test-redis.php:10
    Stack trace:
    #0 /test-redis.php(10): Redis->connect('127.0.0.1', 6379)
    #1 {main}
      thrown in /test-redis.php on line 10
    

    … so it looks like you’re, sadly, right.

    Plugin Author Till Krüss

    (@tillkruess)

    Your hosting provider can probably help you with those permissions. I don’t have any pointers that come to mind.

    Thread Starter ellmann creative

    (@ellmanncreative)

    Yeah, we already reached out to them, as it’s clear that this is something only they can help with.

    Thank you for your time.

    Thread Starter ellmann creative

    (@ellmanncreative)

    I have discussed the issue with out webhost, and as I understand it – the REDIS instance that the website uses is separate from any CLI instance (as it’s managed by web services/containers instead). As such, it is not possible to connect to the same instance from CLI.

    I see three ways to resolve this issue:

    a) the REDIS plugin must refuse execution (return) if ran by CRON (this is the obvious solution),

    b) I must find a separate, out-of-system solution to run WP-CRON, and

    c) I cannot use REDIS for my website.

    Does your plugin have any reason to perform tasks during a WP-CRON run?

    Thoughts?

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Issue with cron – Connection Refused’ is closed to new replies.