【发布时间】:2013-02-26 23:31:00
【问题描述】:
我的本地主机上的 Doctrine 2 有一些问题。仅使用一个查询的一页在大约 1.5 秒内加载到本地主机上。同时,在远程服务器上加载大约需要 300 毫秒 (http://gieromaniak.pl/contact)。我不知道可能出了什么问题。是 Doctrine 2 配置还是其他?或者我的服务器上没有一些 PHP 扩展(WAMP - Apache 2.4.2、PHP 5.4.3)?
不过,我包含了我的 Doctrine 配置文件的源代码:
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\DBAL\Types\Type,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSqlLogger;
// include the class loader directly
require_once __DIR__ . '/Doctrine/Common/ClassLoader.php';
$doctrineClassLoader = new ClassLoader('Doctrine', __DIR__ . '/');
$doctrineClassLoader->register();
Config::load('base');
Config::load('database');
if(Config::get('base.mode') == 'development') {
$bProxyGen = TRUE;
} else {
$bProxyGen = FALSE;
}
// Set up caches
$cache = new ArrayCache;
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Metadata Driver
$driverImpl = $config->newDefaultAnnotationDriver($models);
$config->setMetadataDriverImpl($driverImpl);
// Proxy configuration
$config->setProxyDir(PATH_ROOT.Config::get('database.proxy_dir'));
$config->setProxyNamespace(Config::get('database.proxy_namespace'));
$config->setAutoGenerateProxyClasses($bProxyGen);
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'charset' => 'utf8',
'dbname' => 'dbname',
'user' => 'username',
'password' => 'password',
);
// Create EntityManager
$entityManager = EntityManager::create($connectionOptions, $config);
提前感谢您的帮助!
【问题讨论】:
-
你在远程服务器上的服务器配置是什么?
-
@bleuscyther PHP 5.3.21, Linux, Apache 2. 还需要别的吗?
-
我曾经将 Wamp 作为本地机器测试。我切换到 Xampp,但我可以确认 Wamp/Xampp/Windows 上的过程比 Linux 上的要慢。此外,如果您想提高性能,您应该使用代理和缓存。 docs.doctrine-project.org/en/latest/reference/…
-
本地有操作码缓存吗?因为这有很大的不同。还可以考虑使用元数据缓存,尤其是在您的配置是注释驱动的情况下。
-
@bleuscyther 如您所见,我正在使用 ArrayCache 和代理。但是,不知道为什么,代理类(“CG”等)没有在所需的目录中生成(在远程服务器上没关系)。
标签: php performance configuration doctrine-orm wamp