8000 [Config] Do not use absolute path when computing the vendor freshness · symfony/symfony@3100268 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3100268

Browse files
committed
[Config] Do not use absolute path when computing the vendor freshness
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.
1 parent 04b9ce3 commit 3100268

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Symfony/Component/Config/Resource/ComposerResource.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ private static function refresh()
7171
{
7272
self::$runtimeVendors = [];
7373

74+
$i = 0;
7475
foreach (get_declared_classes() as $class) {
7576
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
7677
$r = new \ReflectionClass($class);
7778
$v = \dirname(\dirname($r->getFileName()));
7879
if (file_exists($v.'/composer/installed.json')) {
79-
self::$runtimeVendors[$v] = @filemtime($v.'/composer/installed.json');
80+
self::$runtimeVendors["__vendor_$i"] = @filemtime($v.'/composer/installed.json');
81+
++$i;
8082
}
8183
}
8284
}

src/Symfony/Component/Config/Tests/Resource/ComposerResourceTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Config\Tests\Resource;
1313

14-
use Composer\Autoload\ClassLoader;
1514
use PHPUnit\Framework\TestCase;
1615
use Symfony\Component\Config\Resource\ComposerResource;
1716

@@ -21,11 +20,10 @@ public function testGetVendor()
2120
{
2221
$res = new ComposerResource();
2322

24-
$r = new \ReflectionClass(ClassLoader::class);
2523
$found = false;
2624

2725
foreach ($res->getVendors() as $vendor) {
28-
if ($vendor && 0 === strpos($r->getFileName(), $vendor)) {
26+
if ($vendor && 0 === strpos('__vendor_0', $vendor)) {
2927
$found = true;
3028
break;
3129
}

0 commit comments

Comments
 (0)
0