Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 这条原则太慢了_Php_Symfony_Doctrine Orm_Doctrine - Fatal编程技术网

Php 这条原则太慢了

Php 这条原则太慢了,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,下面是一些代码: $paths = array(APP_LIBS.DIRECTORY_SEPARATOR.'Doctrine'.DIRECTORY_SEPARATOR.'Entity'); // the connection configuration $dbParams = array( 'dbname' => $di->get('config')->database->dbname, 'user' => $di->get('c

下面是一些代码:

  $paths = array(APP_LIBS.DIRECTORY_SEPARATOR.'Doctrine'.DIRECTORY_SEPARATOR.'Entity');

  // the connection configuration
  $dbParams = array(
    'dbname' => $di->get('config')->database->dbname,
    'user' => $di->get('config')->database->username,
    'password' => $di->get('config')->database->password,
    'host' => $di->get('config')->database->host,
    'port' => (int)$di->get('config')->database->port,
    'charset'  => 'UTF8',
    'driver' => 'pdo_mysql'
  );

  $config = Setup::createAnnotationMetadataConfiguration($paths, $di->get('env')->isDebugActive(), APP_PATH_CACHE_DOCTRINE, null, false);

  $config->setAutoGenerateProxyClasses($di->get('env')->isDev());

  $driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();

  $cachedAnnotationReader = $config->getMetadataDriverImpl()->getReader();
  \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);

  $driverChain->addDriver($config->getMetadataDriverImpl(), "Doctrine\Entity");

  $config->setMetadataDriverImpl($driverChain);
  if ((bool)$di->get('config')->application->sqlLog)
  {
    $config->setSQLLogger(new \Doctrine\Logger\FileSQLLogger());
  }
  $config->addCustomNumericFunction('RAND', 'Doctrine\Custom\Functions\Rand');
  $config->addCustomStringFunction('REGEXP', 'Doctrine\Custom\Functions\Regexp');
  $config->addCustomStringFunction('CONCAT_WS', 'Doctrine\Custom\Functions\ConcatWs');

  // create event manager and hook preferred extension listeners
  $evm = new Doctrine\Common\EventManager();

  // gedmo extension listeners, remove which are not used

  // sluggable
  $sluggableListener = new Gedmo\Sluggable\SluggableListener;
  // you should set the used annotation reader to listener, to avoid creating new one for mapping drivers
  $sluggableListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($sluggableListener);

  // tree
  $treeListener = new Gedmo\Tree\TreeListener;
  $treeListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($treeListener);

  // loggable, not used in example
  $loggableListener = new Gedmo\Loggable\LoggableListener;
  $loggableListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($loggableListener);

  // timestampable
  $timestampableListener = new Gedmo\Timestampable\TimestampableListener;
  $timestampableListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($timestampableListener);

  // translatable
  $translatableListener = new Gedmo\Translatable\TranslatableListener;
  // current translation locale should be set from session or hook later into the listener
  // most important, before entity manager is flushed
  $translatableListener->setTranslatableLocale('en');
  $translatableListener->setDefaultLocale('en');
  $translatableListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($translatableListener);

  // sortable, not used in example
  $sortableListener = new Gedmo\Sortable\SortableListener;
  $sortableListener->setAnnotationReader($cachedAnnotationReader);
  $evm->addEventSubscriber($sortableListener);

  // mysql set names UTF-8 if required
  $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());

  $entityManager = EntityManager::create($dbParams, $config, $evm);

  $platform = $entityManager->getConnection()->getDatabasePlatform();

  \Doctrine\DBAL\Types\Type::addType('json', '\Sonata\Doctrine\Types\JsonType');
  $platform->registerDoctrineTypeMapping("json", 'json');
  $platform->registerDoctrineTypeMapping('enum', 'string');

这非常慢,大约2秒。如果有机会使它更快,您可以使用
xhprof
php扩展来分析您的应用程序,并获得慢代码函数或部分代码。在分析之后,您可以得到图形调用函数,并像这样对该图形计时

您应该向配置中添加
元数据缓存

$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache());

文档:

差不多,但我无法在Debianten上安装APC。请使用一个或多个受支持的驱动程序(redis/memcache(d)/xcache)查看链接文档的详细信息。对,我是用“redis”完成的。它甚至没有变得更快:)