Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

php - Symfony 2.7 cache:clear command checks every database connection

I just have upgraded to symfony 2.7, and have a annoying behaviour.

Some connections in my config.yml are optionables, and describe foreign databases that are not intended to be used in every prod instances.

When doing a cache:clear , it seems that now every connections are checked, even if I don't want them to be active on a particular server.

When setting the --no-warmup option, the problem occurs half the time

php app/console cache:clear --env=prod --no-warmup --verbose

[DoctrineDBALExceptionConnectionException]
An exception occured in driver: SQLSTATE[42000] [1049] Unknown database 'bal_syncrho_database'

Exception trace: () at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:103 DoctrineDBALDriverAbstractMySQLDriver->convertException() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:133 DoctrineDBALDBALException::driverException() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:47 DoctrineDBALDriverPDOMySqlDriver->connect() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:360 DoctrineDBALConnection->connect() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:429 DoctrineDBALConnection->getDatabasePlatformVersion() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:389 DoctrineDBALConnection->detectDatabasePlatform() at /var/www/ror3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:328 DoctrineDBALConnection->getDatabasePlatform() at /var/www/ror3/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:763 DoctrineORMMappingClassMetadataFactory->getTargetPlatform() at /var/www/ror3/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:616 DoctrineORMMappingClassMetadataFactory->completeIdGeneratorMapping() at /var/www/ror3/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:174 DoctrineORMMappingClassMetadataFactory->doLoadMetadata() at /var/www/ror3/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332 DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->loadMetadata() at /var/www/ror3/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78 DoctrineORMMappingClassMetadataFactory->loadMetadata() at /var/www/ror3/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216 DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->getMetadataFor() at /var/www/ror3/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115 DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->getAllMetadata() at /var/www/ror3/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:69 SymfonyBridgeDoctrineCacheWarmerProxyCacheWarmer->warmUp() at /var/www/ror3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:48 SymfonyComponentHttpKernelCacheWarmerCacheWarmerAggregate->warmUp() at /var/www/ror3/app/bootstrap.php.cache:2641 SymfonyComponentHttpKernelKernel->initializeContainer() at /var/www/ror3/app/bootstrap.php.cache:2411 SymfonyComponentHttpKernelKernel->boot() at /var/www/ror3/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70 SymfonyBundleFrameworkBundleConsoleApplication->doRun() at /var/www/ror3/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120 SymfonyComponentConsoleApplication->run() at
/var/www/ror3/app/console:27

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Doctrine is trying to determine the Database Platform Version.

You can avoid this behaviour adding in the Doctrine DBAL Configuration the server version. From the doc:

The server_version option was added in Doctrine DBAL 2.5, which is used by DoctrineBundle 1.3. The value of this option should match your database server version (use postgres -V or psql -V command to find your PostgreSQL version and mysql -V to get your MySQL version).

If you don't define this option and you haven't created your database yet, you may get PDOException errors because Doctrine will try to guess the database server version automatically and none is available.

As example:

#config.yml

doctrine:
    dbal:
    ...
        server_version:       5.6

Hope this help


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...