Skip to content

Commit

Permalink
[Config] Do not use absolute path when computing the vendor freshness
Browse files Browse the repository at this point in the history
When one uses Docker with a different mounting point between CLI & FPM,
the cache keeps regenerating because the ComposerResource class see a
different path for each SAPI. For example `/home/app/app/vendor` vs `/var/www/app/vendor`.
So if you hit FPM, then the CLI, then FPM, each time a new cache is
generated. So the application is quite slow in dev env. And for people
on MacOSX (with docker) is a big pain! And obvisouly, this never
stabilizes !

This occurs a lot when you have a worker, that crash and reboot in the
background, and you browse the web interface. Or when you have something
that hit your API every X secondes, and you are working on a worker.
  • Loading branch information
lyrixx committed Jul 17, 2019
1 parent 04b9ce3 commit 6b30fc0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/Config/Resource/ComposerResource.php
Expand Up @@ -71,12 +71,14 @@ private static function refresh()
{
self::$runtimeVendors = [];

$i = 0;
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$v = \dirname(\dirname($r->getFileName()));
if (file_exists($v.'/composer/installed.json')) {
self::$runtimeVendors[$v] = @filemtime($v.'/composer/installed.json');
self::$runtimeVendors["__vendor_$i"] = @filemtime($v.'/composer/installed.json');
++$i;
}
}
}
Expand Down
Expand Up @@ -21,11 +21,10 @@ public function testGetVendor()
{
$res = new ComposerResource();

$r = new \ReflectionClass(ClassLoader::class);
$found = false;

foreach ($res->getVendors() as $vendor) {
if ($vendor && 0 === strpos($r->getFileName(), $vendor)) {
if ($vendor && 0 === strpos('__vendor_0', $vendor)) {
$found = true;
break;
}
Expand Down

0 comments on commit 6b30fc0

Please sign in to comment.