• Resolved lucas6888

    (@lucas6888)


    Hello, I’m making a new topic to understand the matter well. First of all, great plugin! However, I encountered an issue with a WP-CLI command scheduled on cron jobs, that essentially calls a PHP script that updates prices and stocks from a CSV downloaded with cURL. The script returns the following error at the very beginning:

    PHP Fatal error: Uncaught Error: Call to undefined function apcu_fetch() in /va r/www/html/wp-content/object-cache.php:224

    I suppose the cache doesn’t work in the CLI, what is the best way to solve this? Should I modify php.ini to enable it, as I was reading around, change the name of the object-cache.php temporarily or something else? My concern here is I have lots of WooCommerce products and to say one, Docket Cache needs a bit of tweaking to work well, is this plugin the same? Should it be used with WooCommerce or it will cause wrong prices and stocks to be displayed, especially if I change the object-cache.php file name during script execution?

    Bonus question: I use Redis on another website, should I have the same concerns with it/Memcached too?

    Thank you

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author docjojo

    (@docjojo)

    Hello, do not rename the object-cache.php!
    Docket Cache is not related and you should not run multiple cache plugins at the same time.
    Redis is a different story –?but the problem you face could be related, as the extension needs to be activated for CLI.

    Set
    apc.enable_cli=1
    in your php.ini or conf.d/20-apcu.ini

    Then put this into a script file and run from cli.

    <?php

    $apcu_cache=apcu_cache_info(true);

    if ($apcu_cache)

    {

    $apcu_mem = apcu_sma_info();

    echo 'APCu memory: ', ($apcu_mem['num_seg']*$apcu_mem['seg_size']), ' bytes.';

    echo "\n";

    $testKey='atec_apcu_test_key';

    apcu_add($testKey,'hello');

    $success=apcu_fetch($testKey)=='hello';

    if ($success) echo 'APCu is writeable.';

    else echo 'APCu writing to cache failed.';

    echo "\n";

    if ($success) apcu_delete($testKey);

    }

    ?>







    Thread Starter lucas6888

    (@lucas6888)

    Thank you for the fast reply, I added that line in php.ini for the current version of PHP I’m using, because it wasn’t there already, but it still doesn’t work and throwed the same error. Should it be already there set to 0, or I should write it in a specific location?

    Plugin Author docjojo

    (@docjojo)

    run

    php --info|grep APCu

    and see what happens, looks to me like you do not have apcu enabled at all.

    Thread Starter lucas6888

    (@lucas6888)

    Returns nothing indeed, but still the plugin is active, Query Monitor detects it, and queries are actually cached. Also, the error above shows it should be enabled since it interferes with the script…

    Plugin Author docjojo

    (@docjojo)

    the plugin will only install the object-cache if APCu is enabled.

    if (extension_loaded(‘apcu’) && apcu_enabled())

    Maybe your config changed in the meantime.
    But you should get an error message on the atec-cache-apcu dashboard that APCu is not enabled.

    Thread Starter lucas6888

    (@lucas6888)

    As you can see here:

    https://ibb.co/SyjNVpm

    the object cache is activated.

    Plugin Author docjojo

    (@docjojo)

    well then something is wrong with your setup.
    did you restart php after changing the php.ini ?

    Thread Starter lucas6888

    (@lucas6888)

    I restarted Apache, what do you mean by restarting PHP? Could you provide the command?

    Plugin Author docjojo

    (@docjojo)

    depends on your config and os.
    this might help:

    https://serverfault.com/questions/189940/how-do-you-restart-php-fpm


    Thread Starter lucas6888

    (@lucas6888)

    I was able to solve the issue, here is how in case someone else will need it:

    Even if Query Monitor said the APCu extension was enabled, there wasn’t any extension=apcu.so line in php.ini, so I added it. Now php -i | grep apcu gave the error

    PHP Warning: PHP Startup: Unable to load dynamic library ‘apcu.so’ (tried: /usr/lib/php/20230831/apcu.so)

    So I actually installed the APCu extension for my current PHP version with

    sudo apt-get install php8.3-apcu

    And now the grep command above said apcu was already enabled in /etc/php/8.3/cli/conf.d/20-apcu.ini, so I deleted the line in php.ini and added apc.enable_cli=1 in 20-apcu.ini. Now It works perfectly.

    Plugin Author docjojo

    (@docjojo)

    good.
    like i said, there is an issue with your apcu config.
    .ini files in conf.d folder are loaded when php.ini is loaded, so you can please the option in either one but not in both files.

    of course i could ask if apcu exists with every call but that would slow things down – and the object-cache i have written is the fastest cache compared to any other solution.

    see here.

    https://ps.w.org/atec-cache-apcu/assets/screenshot-6.png?rev=3163707

    Thread Starter lucas6888

    (@lucas6888)

    Can’t even argue, it gave amazing performance from the start (products page generation time from 2.10s to 0.50s) and apart from this, I had no fatal errors during navigation on backend like it used to happen with Redis (even though I don’t know if I misconfigured it, I know of many cases of corrupted data or broken sites). I’ll consider using your plugin on my other website as well. Keep up the good work and thanks for your help!

    Plugin Author docjojo

    (@docjojo)

    you are welcome.
    would appreciate a positive review.
    and try the other plugins too!

    Thread Starter lucas6888

    (@lucas6888)

    I will certainly do both.

    Plugin Author docjojo

    (@docjojo)

    great.
    tnx!

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.