4

I would like to preapare the app.php file with Symfony 2.1 and APC. I took the Symfony standard edition configured it with doctrine and then made changes described here: http://symfony.com/doc/2.1/book/performance.html

<?php
require_once __DIR__.'\..\vendor\symfony\symfony\src\Symfony\Component\ClassLoader\UniversalClassLoader.php';
require_once __DIR__.'\..\vendor\symfony\symfony\src\Symfony\Component\ClassLoader\ApcUniversalClassLoader.php';
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);

require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
?>

but it is not working, I got error:

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in __my_path__\app\AppKernel.php on line 7

How should I prepare the app.php for best performance.

Dimitry Orgonov
  • 198
  • 1
  • 7

1 Answers1

6

Take a look at the default app.php file in the Symfony Standard Distribution. In order to enable APC your app.php file should look like this:

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.

$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);

require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

You can also improve performance if you enable the symfony gateway cache by uncommenting the require_once __DIR__.'/../app/AppCache.php'; and $kernel = new AppCache($kernel); lines.

Juan Sosa
  • 5,262
  • 1
  • 35
  • 41
  • Thanks it is working good. I removed the line with: Request::enableHttpMethodParameterOverride(); because it is from Symfony 2.2 and I'm using Symfony 2.1. Do I need to additionally register any namespaces? – Dimitry Orgonov Mar 04 '13 at 07:58
  • You are right about the `Request::enableHttpMethodParameterOverride(); ` line. I've edited the answer. Please, accept it if it worked for you. – Juan Sosa Mar 04 '13 at 11:17
  • make sure to add localhost to trusted proxies if you do any IP authentication in your security.yml or controllers and enable gateway cache. see http://stackoverflow.com/a/16895859/1443717 and http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html – StrikeForceZero Aug 15 '14 at 04:19