Description
http://symfony.com/doc/2.8/performance.html#caching-the-autoloader-with-apc
This page currently has its app.php example written like this:
// app.php
// ...
use Symfony\Component\ClassLoader\ApcClassLoader;
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance
// Change 'sf2' by the prefix you want in order
// to prevent key conflict with another application
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
// ...
The problem is bootstrap.php.cache also sets $loader
with this line up near the top with something like this:
$loader = require_once __DIR__.'/./autoload.php';
Because autoload.php was already loaded once, this line from bootstrap.php.cache sets $loader
to true
. Later in web/app.php, calling new ApcClassLoader('sf2', $loader);
throws the following error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The class finder must implement a "findFile" method.' in /var/www/my_project/app/bootstrap.php.cache:2869 Stack trace:
# 0 /var/www/my_project/web/app.php(18): Symfony\Component\ClassLoader\ApcClassLoader->__construct('my_project', true)
# 1 /var/www/my_project/web/index.php(17): include_once('/var/www/my_project...')
# 2 {main} thrown in /var/www/my_project/app/bootstrap.php.cache on line 2869
Because $loader
is true
and no longer an instance of ClassLoader
.
I entered this as an issue without a pull request because I wasn't sure what the fix should be. Users could be told to comment out $loader = require __DIR__.'/../app/autoload.php';
from web/app.php in the documentation, but I'm not sure if there's a better way to handle it.
Steps to reproduce:
- Make sure you have apc enabled
- Download and configure Symfony 2.8 project
- Change web/app.php to match the example code above.
- Try to visit app.php in your browser.
- This should trigger the error I pasted above.
I did not test with other versions of Symfony.