ZF-8554: Clean Zend_Loader_PluginLoader cache

Description

Hello.

We're using the PluginLoader cache in a high-frequented website. Therefore our deployment system deletes the cache file on every deployment run, when plugin files got deleted or moved. Now we ran into the problem that the cache was re-created incomplete. The opening <?php tag was missing in the file.

We could track this problem to the _appendIncFile method in Zend_Loader_PluginLoader. protected static function _appendIncFile($incFile) { if (!file_exists(self::$_includeFileCache)) { $file = '<?php'; } else { $file = file_get_contents(self::$_includeFileCache); } if (!strstr($file, $incFile)) { $file .= "\ninclude_once '$incFile';"; file_put_contents(self::$_includeFileCache, $file); } }

Following scenario happens: - The PHP process works on the first if condition and finds the still existing cache file. => Jumps to else block. - A new deployment is simultaneous started, which has to delete the cache file (plugin files were moved or deleted). This happens in the time after the PHP process calls the file_exists and tries in the next step a file_get_contents. - The PHP process now tries to get the file with file_get_contents. Because the file is missing $file gets the value false. - Adding the next include_once to the variable and calling file_put_contents ends up in a cache file without an starting <?php tag. => Our website stops working, because this non php file gets included on every call producing unwanted output.

We're not sure if this is a bug of the _appendIncFile or it's just wrong to delete the cache file and there's another option to clean it up and start his recreation.

We think this could be fixed, when the file_get_contents is directly called (before any file_exists). If the returned value is false the string should get a <?php tag assigned as string value.

Comments

Hi,

we created a patch for this issue.

Would be great to see this or a similar solution in one oft the next releases.

Best Regards, Tobias.

Are you sure that this doenst raise notices of non existing files? I will look into this bug and a solution during the next bughunt days.

You're right, a warning will be raised, not ideal. But this also also currently the case when our described scenario happens.

Added an advanced patch to reduce the warnings