0

I've got some problems with Doctrine 2 on my localhost. One page, which uses only one query, is loading on localhost in about 1.5s. Meanwhile, on remote server loading takes about 300ms (http://gieromaniak.pl/contact). I have no idea what could be wrong. Is it Doctrine 2 configuration or sth else? Or maybe I don't have some PHP extension on my server (WAMP - Apache 2.4.2, PHP 5.4.3)?

Nevertheless, I'm including source code of my Doctrine configuration file:

<?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);

Thank You in advance for any help!

Jazi
  • 6,569
  • 13
  • 60
  • 92
  • what is your server configuration on the remote server? – Jeffrey Nicholson Carré Feb 26 '13 at 23:35
  • @bleuscyther PHP 5.3.21, Linux, Apache 2. Need sth else? – Jazi Feb 26 '13 at 23:42
  • I use to have Wamp as a Local machine test. I switched to Xampp but i can confirm that the process is slower on Wamp/Xampp/Windows than on Linux. ALso you should use proxies and cache if you want to improve the performance. http://docs.doctrine-project.org/en/latest/reference/improving-performance.html – Jeffrey Nicholson Carré Feb 26 '13 at 23:48
  • Do you have an opcode cache locally? Because that makes a huge difference. Also consider using a metadata cache, especially if your configuration is annotation-driven. – Ocramius Feb 26 '13 at 23:50
  • @bleuscyther As You should see, I'm using ArrayCache and Proxy. But, do not know why, Proxy classes ("__CG__" etc.) aren't generating in desired directory (on remote server it's all right). – Jazi Feb 26 '13 at 23:52
  • @Ocramius First, tell me what's "opcode cache", and then I will tell You if I have this :D? – Jazi Feb 26 '13 at 23:54
  • yes :), sorry, i overlooked the code . On windows you can clear the temporary folder. You are using array cache on dev ( so it's ok ). Opcode cache like APC or Memcached are recommanded on production – Jeffrey Nicholson Carré Feb 26 '13 at 23:57
  • @bleuscyther So I know. But still... localhost is dev and I need to run it faster :). – Jazi Feb 27 '13 at 00:00
  • http://stackoverflow.com/questions/5740114/my-doctrine-is-really-slow-simple-query-and-one-second-to-get-the-result – Jeffrey Nicholson Carré Feb 27 '13 at 00:02
  • I don't think it's Doctrine , i think its web dev on windows home edition that sucks :). You can increase mysql perf. And also increase the memory limit allocated to php on tour php.ini file put it to 512M – Jeffrey Nicholson Carré Feb 27 '13 at 00:07
  • @bleuscyther Well... increased memory limit didn't helped. I've also added `skip-name-resolve` line to my "my.ini" file... and it's still the same... :( – Jazi Feb 27 '13 at 00:27
  • @bleuscyther I've also other projects on my WAMP server. They're not based on Doctrine (it's Kohana Framework) and they work fine. So... maybe mysql perf is ok? – Jazi Feb 27 '13 at 00:29

1 Answers1

0

I would recommand to install apc and to improve mysql performance:

Install APC

I strongly recommend to use Wamp server (x86) for that, the apc.dll for the x64 version of windows doesn't work well.

follow this tutorial with the following modifications:

  • the link to apc.dll
  • find the Zend Extension Build or PHP Extension Build ,from your phpinfo(); you can use that http://localhost/?phpinfo=1 for your WAMP localhost
  • the Zend Extension Build should be like this :

API220100525,TS,VC9

  • Note the TS word, it can be blank; look if their is a different word like NTS
  • download the latest version according to the TS or NTS value
  • rename the dll php_apc.dll
  • put the php_apc.dll in YourWampFolder/bin/php/ext/
  • there are 2 php.ini files in wamp : wamp\bin\apache\apacheX.X.XX\bin\ and wamp\bin\php\phpX.X.X\ (replace the X.X... by your versions) write extension=php_apc.dll; in both of them
  • close/open Wamp (not restart)
  • from the wamp icon->php->PHP extensions->php_apc.dll check to activate
  • restart wamp

you can verify that APC is running by downloading the apc.php file into your project dirctory. You will find it in the compressed file available at the PECL website. Take the latest version.

Now from your browser : http://localhost/yourproject/apc.php

You can modify the settings of APC from php.ini (try both)

exemple :

//php.ini
...

[APC]
apc.ttl=7200
apc.user_ttl=7200
apc.shm_segments=3
apc.shm_size=90M
apc.max_file_size = 2M
apc.include_once_override = 1

just in case you want to clear the cache

// resetcache.php
<?php
if ( $_GET['pass'] == 'yes') {
if(function_exists('apc_clear_cache')){
        if (apc_clear_cache() && apc_clear_cache('user'))
                print 'All Clear!';
        else
                print 'Clearing Failed!';

        print '<pre>';
        print_r(apc_cache_info());
        print '</pre>';
}else print "fuction_doesn't exist";
        } else {
        print 'Authenticate, please!';
}

i put some extra security to prevent unwanted access but do not include apc.php and clearcache.php in the production server.

Increase Mysql performance

  1. link1
  2. link2
  3. link3

Clean local machine

You can clean your browser cache and temp folders. CCleaner

This is all that i did to increase the speed of Doctrine2 on my local machine in the past. you can also monitor the Ram used by Mysql/Apache process to see if you don' t need to buy/allocate more RAM.

Community
  • 1
  • 1
Jeffrey Nicholson Carré
  • 2,950
  • 1
  • 26
  • 44
  • :( change apc.shm_segments=1, try other settings to see if that helps,http://stackoverflow.com/questions/8583253/what-could-cause-local-apc-to-be-slower-than-remote-memcached and – Jeffrey Nicholson Carré Feb 28 '13 at 03:06