8000 bug #36169 [HttpKernel] fix locking for PHP 7.4+ (nicolas-grekas) · symfony/symfony@7f5d017 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f5d017

Browse files
bug #36169 [HttpKernel] fix locking for PHP 7.4+ (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] fix locking for PHP 7.4+ | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #36132 | License | MIT | Doc PR | - As explained in https://bugs.php.net/79398 Commits ------- f618b98 [HttpKernel] fix locking for PHP 7.4+
2 parents 099481f + f618b98 commit 7f5d017

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
3939
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
4040

41-
// Help opcache.preload discover always-needed symbols
42-
class_exists(ConfigCache::class);
43-
4441
/**
4542
* The Kernel is the heart of the Symfony system.
4643
*
@@ -533,47 +530,20 @@ protected function initializeContainer()
533530
try {
534531
is_dir($cacheDir) ?: mkdir($cacheDir, 0777, true);
535532

536-
if ($lock = fopen($cachePath, 'w')) {
537-
chmod($cachePath, 0666 & ~umask());
533+
if ($lock = fopen($cachePath.'.lock', 'w')) {
538534
flock($lock, LOCK_EX | LOCK_NB, $wouldBlock);
539535

540536
if (!flock($lock, $wouldBlock ? LOCK_SH : LOCK_EX)) {
541537
fclose($lock);
542-
} else {
543-
$cache = new class($cachePath, $this->debug) extends ConfigCache {
544-
public $lock;
545-
546-
public function write($content, array $metadata = null)
547-
{
548-
rewind($this->lock);
549-
ftruncate($this->lock, 0);
550-
fwrite($this->lock, $content);
551-
552-
if (null !== $metadata) {
553-
file_put_contents($this->getPath().'.meta', serialize($metadata));
554-
@chmod($this->getPath().'.meta', 0666 & ~umask());
555-
}
556-
557-
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
558-
@opcache_invalidate($this->getPath(), true);
559-
}
560-
}
561-
562-
public function release()
563-
{
564-
flock($this->lock, LOCK_UN);
565-
fclose($this->lock);
566-
}
567-
};
568-
$cache->lock = $lock;
569-
570-
if (!\is_object($this->container = include $cachePath)) {
571-
$this->container = null;
572-
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
573-
$this->container->set('kernel', $this);
574-
575-
return;
576-
}
538+
$lock = null;
539+
} elseif (!\is_object($this->container = include $cachePath)) {
540+
$this->container = null;
541+
} elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) {
542+
flock($lock, LOCK_UN);
543+
fclose($lock);
544+
$this->container->set('kernel', $this);
545+
546+
return;
577547
}
578548
}
579549
} catch (\Throwable $e) {
@@ -637,8 +607,10 @@ public function release()
637607
}
638608

639609
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
640-
if (method_exists($cache, 'release')) {
641-
$cache->release();
610+
611+
if ($lock) {
612+
flock($lock, LOCK_UN);
613+
fclose($lock);
642614
}
643615

644616
$this->container = require $cachePath;

0 commit comments

Comments
 (0)
0