phpsymfonycachingdoctrineapcu

How to use ApcuCache with Symfony, Doctrine ORM and DoctrineCacheBundle


Before I was stuck with this problem the project was running on PHP5.6 on SF2.6.

Now I'm using PHP7.1.20 with SF2.8. I installed apcu along with apcu_bc inside my docker container and enabled the apcu php module.

Now the error is:

UndefinedFunctionException in ApcCache.php line 35:
Attempted to call function "apc_exists" from the global namespace.

When I change the actual function calls inside of the loaded ApcCache-Class from apc_ to apcu_ everything works fine.

Inside Doctrine\Common\Cache are both classes, the ApcCache- and the ApcuCache-Class. I don't know how I can tell doctrine ORM/CacheBundle to use the ApcuCache-Class instead of the Apc one.

Doctrine Config:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                persistent: true
                wrapper_class: 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection'
                driver_class: 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Driver\PDOMySql\Driver'
                server_version: '5.7'
                options:
                    x_reconnect_attempts: 3
            jato:
                driver:   "%database_jato_driver%"
                host:     "%database_jato_host%"
                port:     "%database_jato_port%"
                dbname:   "%database_jato_name%"
                user:     "%database_jato_user%"
                password: "%database_jato_password%"
                charset:  UTF8
                persistent: true
                server_version: '5.7'
          
            drupal:
                driver:   "%database_drupal_driver%"
                host:     "%database_drupal_host%"
                port:     "%database_drupal_port%"
                dbname:   "%database_drupal_name%"
                user:     "%database_drupal_user%"
                password: "%database_drupal_password%"
                charset:  UTF8
                persistent: true
                server_version: '5.7'

        types:
            json: Sonata\Doctrine\Types\JsonType

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    SonataMediaBundle: ~
                    ApplicationSonataMediaBundle: ~
                    XFrontendBundle: ~
                query_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache
                metadata_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache
                result_cache_driver:
                    type: service
                    id: doctrine_cache.providers.chain_cache

            jato:
                connection: jato
                mappings:
                    XBackendBundle: ~
                query_cache_driver: array
                metadata_cache_driver: array
                result_cache_driver: array
            drupal:
                connection: drupal

DoctrineCacheBundle Config:

doctrine_cache:
    providers:
        chain_cache:
            chain:
                providers: [array_cache, apc_cache]
        apc_cache:
            type: apc
        array_cache:
            type: array

Inside the cached service container (app/cache/prod/appProdProjectContainer.php) I can find the following information:

'doctrine_cache.providers.apc_cache' => 'getDoctrineCache_Providers_ApcCacheService',

followed by

/*
     * Gets the public 'doctrine_cache.providers.apc_cache' shared service.
     *
     * @return \Doctrine\Common\Cache\ApcCache
     */
    protected function getDoctrineCache_Providers_ApcCacheService()
    {
        return $this->services['doctrine_cache.providers.apc_cache'] = new \Doctrine\Common\Cache\ApcCache();
    }

and

 'validator.mapping.cache.apc.class' => 'Symfony\\Component\\Validator\\Mapping\\Cache\\ApcCache',

and

'doctrine_cache.apc.class' => 'Doctrine\\Common\\Cache\\ApcCache',
'doctrine.orm.cache.apc.class' => 'Doctrine\\Common\\Cache\\ApcCache',

what do i need to configure or update etc to achieve that only the ApcuCache-Class gets used instead of Apc.

additional composer infos:

doctrine/cache                           v1.8.0
doctrine/annotations                     v1.6.0             
doctrine/cache                           v1.8.0             
doctrine/collections                     v1.5.0             
doctrine/common                          v2.9.0             
doctrine/dbal                            v2.4.5             
doctrine/doctrine-bundle                 1.6.13             
doctrine/doctrine-cache-bundle           dev-master 
doctrine/event-manager                   v1.0.0             
doctrine/inflector                       v1.3.0             
doctrine/instantiator                    1.1.0              
doctrine/lexer                           v1.0.1             
doctrine/orm                             v2.4.8             
doctrine/persistence                     v1.0.1             
doctrine/reflection                      v1.0.0  

symfony/assetic-bundle                   v2.8.2             
symfony/monolog-bundle                   v2.12.1           
symfony/polyfill-apcu                    v1.9.0             
symfony/polyfill-ctype                   v1.9.0             
symfony/polyfill-intl-icu                v1.9.0             
symfony/polyfill-mbstring                v1.9.0             
symfony/polyfill-php54                   v1.9.0             
symfony/polyfill-php55                   v1.9.0             
symfony/polyfill-php56                   v1.9.0             
symfony/polyfill-php70                   v1.9.0             
symfony/polyfill-util                    v1.9.0             
symfony/security-acl                     v3.0.1             
symfony/swiftmailer-bundle               v2.6.7             
symfony/symfony                          v2.8.45

sonata-project/admin-bundle              3.39.0             
sonata-project/block-bundle              3.12.1             
sonata-project/cache                     2.0.1              
sonata-project/core-bundle               3.11.2             
sonata-project/datagrid-bundle           2.3.1              
sonata-project/doctrine-extensions       1.0.2              
sonata-project/doctrine-orm-admin-bundle 3.4.2              
sonata-project/easy-extends-bundle       2.5.0              
sonata-project/exporter                  1.9.1              
sonata-project/formatter-bundle          3.5.0              
sonata-project/intl-bundle               2.5.0              
sonata-project/jquery-bundle             1.10.2             
sonata-project/markitup-bundle           2.1.0              
sonata-project/media-bundle              3.15.0 

container debug information:

Information for Service "doctrine_cache.providers.apc_cache"
============================================================

 ------------------ ------------------------------------
  Option             Value
 ------------------ ------------------------------------
  Service ID         doctrine_cache.providers.apc_cache
  Class              Doctrine\Common\Cache\ApcCache
  Tags               -
  Scope              container
  Public             yes
  Synthetic          no
  Lazy               no
  Synchronized       no
  Abstract           no
  Autowired          no
  Autowiring Types   -
 ------------------ ------------------------------------    

I guess this is the right service that I have to configure to use the ApcuCache-Class over the actual ApcCache-Class.

Thanks, guys help is much appreciated.


Solution

  • ... ... ...

    its possible to just override the actual service ...

    @/src/App/Bundle/Resources/config/services.yml :

    doctrine_cache.providers.apc_cache:
            class: Doctrine\Common\Cache\ApcuCache
    

    well.. first time symfony/doctrine/... learning the hard way...

    any further explanation is still much appreciated.

    have a nice one.