protected function writeCacheFile(string $cacheEntryPathAndFilename, string $data)
    {
        for ($i = 0; $i < 3; $i++) {
            // This can be replaced by a simple file_put_contents($cacheEntryPathAndFilename, $data, LOCK_EX) once vfs
            // is fixed for file_put_contents with LOCK_EX, see https://github.com/mikey179/vfsStream/wiki/Known-Issues
            $result = false;
            try {
                $file = fopen($cacheEntryPathAndFilename, 'wb');
                if ($file === false) {
                    continue;
                }
                if (flock($file, LOCK_EX) !== false) {
                    $result = fwrite($file, $data);
                    flock($file, LOCK_UN);
                }
                fclose($file);
            } catch (\Exception $e) {
            }
            if ($result !== false) {
                clearstatcache(true, $cacheEntryPathAndFilename);
                return $result;
            }
            usleep(rand(10, 500));
        }

        return false;
    }
protected function writeCacheFile(string $cacheEntryPathAndFilename, string $data)
    {
        for ($i = 0; $i < 3; $i++) {
            // This can be replaced by a simple file_put_contents($cacheEntryPathAndFilename, $data, LOCK_EX) once vfs
            // is fixed for file_put_contents with LOCK_EX, see https://github.com/mikey179/vfsStream/wiki/Known-Issues
            $result = false;
            try {
                $file = fopen($cacheEntryPathAndFilename, 'wb');
                if ($file === false) {
                    continue;
                }
                if (flock($file, LOCK_EX) !== false) {
                    $result = fwrite($file, $data);
                    flock($file, LOCK_UN);
                }
                fclose($file);
            } catch (\Exception $e) {
            }
            if ($result !== false) {
                clearstatcache(true, $cacheEntryPathAndFilename);
                return $result;
            }
            usleep(rand(10, 500));
        }

        return false;
    }
protected function writeCacheFile ( string $ cacheEntryPathAndFilename , string $ data ) { for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { // This can be replaced by a simple file_put_contents($cacheEntryPathAndFilename, $data, LOCK_EX) once vfs // is fixed for file_put_contents with LOCK_EX, see https://github.com/mikey179/vfsStream/wiki/Known-Issues $ result = false ; try { $ file = fopen ( $ cacheEntryPathAndFilename , 'wb' ) ; if ( $ file === false ) { continue ; } if ( flock ( $ file , LOCK_EX ) !== false ) { $ result = fwrite ( $ file , $ data ) ; flock ( $ file , LOCK_UN ) ; } fclose ( $ file ) ; } catch ( \ Exception $ e ) { } if ( $ result !== false ) { clearstatcache ( true , $ cacheEntryPathAndFilename ) ; return $ result ; } usleep ( rand ( 10 , 500 ) ) ; } return false ; }
Writes the cache data into the given cache file, using locking.

@param string $cacheEntryPathAndFilename
@param string $data
@return boolean|integer Return value of file_put_contents
Writes the cache data into the given cache file using locking .