Symfony 2 - Attempted to call function "apcu_fetch" from namespace "Doctrine\Common\Cache"
Asked Answered
S

2

8

I'm using PHP7.0.8 and the doctrine cache (with APCU) in my symfony project. When I call function from my controllers which use this cache, no problems, It works fine !

But when I create a command file which use a repository which use the doctrine cache, and when I run this command on my shell, I've the error :

[Symfony\Component\Debug\Exception\UndefinedFunctionException]
Attempted to call function "apcu_fetch" from namespace "Doctrine\Common\Cache".

My configuration :

doctrine:
dbal:
    driver:   pdo_mysql
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        default:
            auto_mapping: true
            mappings:
                StofDoctrineExtensionsBundle: ~
            metadata_cache_driver: apcu
            query_cache_driver: apcu
            result_cache_driver: apcu

The same code works if I run it in a controller :( I think it's a bug, any idea ?

Stupa answered 20/8, 2016 at 13:54 Comment(1)
I have the same problem on CircleCI, even if it's working well on servers and local env. Did you found a solution?Romaic
M
11

I fixed the very same problem by installing AND enabling php-apcu on my ubuntu machine.

sudo apt-get install -y php-apcu

DON'T forget to enable the module:

sudo phpenmod apcu

Double check that php-apcu is loaded in the command line version of your php config. Try to run the following on the command line

php -i | grep apcu

I got something like that as output:

/etc/php/7.0/cli/conf.d/20-apcu.ini,
apcu

which shows me that apcu is loaded.

Malayopolynesian answered 20/9, 2016 at 8:57 Comment(0)
G
2

When you run php from command line, you're actually invoking a php-cli (command line interpreter), not php itself. Php and php-cli are different, they use different config file, and also they can use different extensions. Check you php-cli extensions.

Gupta answered 20/8, 2016 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.