Skip to content

Revert "Propose Opcache invalidation on file operations" #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 2 additions & 45 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public static function copy($src, $dest, $path = null, $useStreams = false)
throw new FilesystemException(sprintf('%1$s(%2$s, %3$s): %4$s', __METHOD__, $src, $dest, $stream->getError()));
}

self::invalidateFileCache($dest);

return true;
}

Expand All @@ -101,8 +99,6 @@ public static function copy($src, $dest, $path = null, $useStreams = false)
throw new FilesystemException(__METHOD__ . ': Copy failed.');
}

self::invalidateFileCache($dest);

return true;
}

Expand Down Expand Up @@ -140,8 +136,6 @@ public static function delete($file)
{
throw new FilesystemException(__METHOD__ . ': Failed deleting ' . $filename);
}

self::invalidateFileCache($file);
}

return true;
Expand Down Expand Up @@ -183,8 +177,6 @@ public static function move($src, $dest, $path = '', $useStreams = false)
throw new FilesystemException(__METHOD__ . ': ' . $stream->getError());
}

self::invalidateFileCache($dest);

return true;
}

Expand All @@ -193,8 +185,6 @@ public static function move($src, $dest, $path = '', $useStreams = false)
throw new FilesystemException(__METHOD__ . ': Rename failed.');
}

self::invalidateFileCache($dest);

return true;
}

Expand Down Expand Up @@ -228,8 +218,6 @@ public static function write($file, &$buffer, $useStreams = false, $appendToFile
$stream->set('chunksize', (1024 * 1024));
$stream->writeFile($file, $buffer, $appendToFile);

self::invalidateFileCache($file);

return true;
}

Expand All @@ -238,16 +226,10 @@ public static function write($file, &$buffer, $useStreams = false, $appendToFile
// Set the required flag to only append to the file and not overwrite it
if ($appendToFile === true)
{
$res = \is_int(file_put_contents($file, $buffer, \FILE_APPEND));
return \is_int(file_put_contents($file, $buffer, \FILE_APPEND));
}
else
{
$res = \is_int(file_put_contents($file, $buffer));
}

self::invalidateFileCache($file);

return $res;
return \is_int(file_put_contents($file, $buffer));
}

/**
Expand Down Expand Up @@ -284,8 +266,6 @@ public static function upload($src, $dest, $useStreams = false)
throw new FilesystemException(sprintf('%1$s(%2$s, %3$s): %4$s', __METHOD__, $src, $dest, $stream->getError()));
}

self::invalidateFileCache($dest);

return true;
}

Expand All @@ -294,8 +274,6 @@ public static function upload($src, $dest, $useStreams = false)
// Short circuit to prevent file permission errors
if (Path::setPermissions($dest))
{
self::invalidateFileCache($dest);

return true;
}

Expand All @@ -304,25 +282,4 @@ public static function upload($src, $dest, $useStreams = false)

throw new FilesystemException(__METHOD__ . ': Failed to move file.');
}

/**
* Invalidate any opcache for a newly written file immediately, if opcache* functions exist and if this was a PHP file.
*
* @param string $file The path to the file just written to, to flush from opcache
*
* @return void
*/
public static function invalidateFileCache($file)
{
if (function_exists('opcache_invalidate'))
{
$info = pathinfo($file);

if (isset($info['extension']) && $info['extension'] === 'php')
{
// Force invalidation to be absolutely sure the opcache is cleared for this file.
opcache_invalidate($file, true);
}
}
}
}