Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.

Commit 1688f3d

Browse files
Fix ZF-11921: Race condition in plugin loader include file cache
This fixes the race condition described at: http://framework.zend.com/issues/browse/ZF-11921 For the race to disappear each and every line is made completely independent from the others. This is the reason why every line includes its own php open and close tag, and no file_get_content() is made, and the file is opened in append only mode. To prevent the insertion of duplicates lines, a fast non blocking lock is made and kept until the end of the request, thus the static $h. Tested on a highly concurrent server without a problem.
1 parent 1474ec6 commit 1688f3d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

library/Zend/Loader/PluginLoader.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,18 @@ public static function getIncludeFileCache()
477477
*/
478478
protected static function _appendIncFile($incFile)
479479
{
480-
if (!file_exists(self::$_includeFileCache)) {
481-
$file = '<?php';
482-
} else {
483-
$file = file_get_contents(self::$_includeFileCache);
480+
static $h = null;
481+
482+
if (null === $h) {
483+
$h = fopen(self::$_includeFileCache, 'ab');
484+
if (!flock($h, LOCK_EX | LOCK_NB, $wb) || $wb) {
485+
$h = false;
486+
}
484487
}
485-
if (!strstr($file, $incFile)) {
486-
$file .= "\ninclude_once '$incFile';";
487-
file_put_contents(self::$_includeFileCache, $file);
488+
489+
if (false !== $h) {
490+
$line = "<?php include_once '$incFile'?>\n";
491+
fwrite($h, $line, strlen($line));
488492
}
489493
}
490494
}

0 commit comments

Comments
 (0)