Tip: Symfony2 Production Settings With Doctrine Checks

I found today a tip from the doctrine configuration and command to check for production settings correctness.

The command in question is the following:

~ php app/console doctrine:ensure-production-settings --env=prod
Proxy Classes are always regenerating.

As you can see even in production server it would want to fail because of the autoregenerate of proxy classes set by the debug flag. Because you want to also not wait until production by try production in your local you want to force this flag to allow to mimic the real slim shady nature of your production server.

To do this run:

~ php app/console doctrine:ensure-production-settings --no-debug --env=prod
PHP Fatal error:  Class 'FOS\UserBundle\Entity\UserListener' not found in /home/cordoval/sites-2/app/cache/prod/appProdProjectContainer.php on line 340
PHP Stack trace: ...

Woah! Not coolio, so obviously the problem is you have forgotten to clear the cache on production. After doing this cache:clear –env=prod then you will be greeted after doing all well with:

~ php app/console doctrine:ensure-production-settings --no-debug --env=prod
Environment is correctly configured for production.

I personally would not bet my heart on these checkers, since if you are using multiple connections for instance I sincerely doubt it checks the settings for each one of them all. However this is a good start to create checks for your production environment, thing largely unexplored in the open source field since everybody assumes you are an expert deploying on production like a boss. My advise is to create checks yourself and maybe open source these checks and share them. Of course the productions settings ensuring command boils down to just 3 checks and for this …

Feel free to override the ORM\Configuration class method if you add more checks or create another similar command that invokes also this logic like “grace:check-system-settings-for-security-and-production“:

  /**
     * Ensures that this Configuration instance contains settings that are
     * suitable for a production environment.
     *
     * @throws ORMException If a configuration setting has a value that is not
     *                      suitable for a production environment.
     */
    public function ensureProductionSettings()
    {
        if ( ! $this->getQueryCacheImpl()) {
            throw ORMException::queryCacheNotConfigured();
        }
 
        if ( ! $this->getMetadataCacheImpl()) {
            throw ORMException::metadataCacheNotConfigured();
        }
 
        if ($this->getAutoGenerateProxyClasses()) {
            throw ORMException::proxyClassesAlwaysRegenerating();
        }
    }

You see here that doctrine only checks its back, naturally just cache configuration, metadata cache, and regeneration of proxy classes. You could add for instance reverse settings, and what not. Share your ideas on the comments below.

I am so thankful I am running in some neat things I have missed for not reading enough. Now by God’s undeserved grace I will do my best to try to blog post and continue the phpspec series.

Encouragements and keep the support up please if you can send me to Warsaw to learn more and share 🙂

Your friend cordoval.

Leave a Reply

Your email address will not be published. Required fields are marked *