src/PhpSigep/Cache/Storage/Adapter/FileSystem.php
protected function getFileContent($file, $nonBlocking = false, & $wouldblock = null)
    {
        $locking    = $this->getOptions()->getFileLocking();
        $wouldblock = null;

        ErrorHandler::start();

        // if file locking enabled -> file_get_contents can't be used
        if ($locking) {
            $fp = fopen($file, 'rb');
            if ($fp === false) {
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error opening file '{$file}'", 0, $err
                );
            }

            if ($nonBlocking) {
                $lock = flock($fp, LOCK_SH | LOCK_NB, $wouldblock);
                if ($wouldblock) {
                    fclose($fp);
                    ErrorHandler::stop();

                    return;
                }
            } else {
                $lock = flock($fp, LOCK_SH);
            }

            if (!$lock) {
                fclose($fp);
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error locking file '{$file}'", 0, $err
                );
            }

            $res = stream_get_contents($fp);
            if ($res === false) {
                flock($fp, LOCK_UN);
                fclose($fp);
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    'Error getting stream contents', 0, $err
                );
            }

            flock($fp, LOCK_UN);
            fclose($fp);

            // if file locking disabled -> file_get_contents can be used
        } else {
            $res = file_get_contents($file, false);
            if ($res === false) {
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error getting file contents for file '{$file}'", 0, $err
                );
            }
        }

        ErrorHandler::stop();

        return $res;
    }
protected function getFileContent($file, $nonBlocking = false, & $wouldblock = null)
    {
        $locking    = $this->getOptions()->getFileLocking();
        $wouldblock = null;

        ErrorHandler::start();

        // if file locking enabled -> file_get_contents can't be used
        if ($locking) {
            $fp = fopen($file, 'rb');
            if ($fp === false) {
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error opening file '{$file}'", 0, $err
                );
            }

            if ($nonBlocking) {
                $lock = flock($fp, LOCK_SH | LOCK_NB, $wouldblock);
                if ($wouldblock) {
                    fclose($fp);
                    ErrorHandler::stop();

                    return;
                }
            } else {
                $lock = flock($fp, LOCK_SH);
            }

            if (!$lock) {
                fclose($fp);
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error locking file '{$file}'", 0, $err
                );
            }

            $res = stream_get_contents($fp);
            if ($res === false) {
                flock($fp, LOCK_UN);
                fclose($fp);
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    'Error getting stream contents', 0, $err
                );
            }

            flock($fp, LOCK_UN);
            fclose($fp);

            // if file locking disabled -> file_get_contents can be used
        } else {
            $res = file_get_contents($file, false);
            if ($res === false) {
                $err = ErrorHandler::stop();
                throw new Exception\RuntimeException(
                    "Error getting file contents for file '{$file}'", 0, $err
                );
            }
        }

        ErrorHandler::stop();

        return $res;
    }
protected function getFileContent ( $ file , $ nonBlocking = false , & $ wouldblock = null ) { $ locking = $ this -> getOptions ( ) -> getFileLocking ( ) ; $ wouldblock = null ; ErrorHandler :: start ( ) ; // if file locking enabled -> file_get_contents can't be used if ( $ locking ) { $ fp = fopen ( $ file , 'rb' ) ; if ( $ fp === false ) { $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error opening file '{$file}'" , 0 , $ err ) ; } if ( $ nonBlocking ) { $ lock = flock ( $ fp , LOCK_SH | LOCK_NB , $ wouldblock ) ; if ( $ wouldblock ) { fclose ( $ fp ) ; ErrorHandler :: stop ( ) ; return ; } } else { $ lock = flock ( $ fp , LOCK_SH ) ; } if ( ! $ lock ) { fclose ( $ fp ) ; $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error locking file '{$file}'" , 0 , $ err ) ; } $ res = stream_get_contents ( $ fp ) ; if ( $ res === false ) { flock ( $ fp , LOCK_UN ) ; fclose ( $ fp ) ; $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( 'Error getting stream contents' , 0 , $ err ) ; } flock ( $ fp , LOCK_UN ) ; fclose ( $ fp ) ; // if file locking disabled -> file_get_contents can be used } else { $ res = file_get_contents ( $ file , false ) ; if ( $ res === false ) { $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error getting file contents for file '{$file}'" , 0 , $ err ) ; } } ErrorHandler :: stop ( ) ; return $ res ; }
Read a complete file

@param  string $file File complete path
@param  bool $nonBlocking Don't block script if file is locked
@param  bool $wouldblock The optional argument is set to TRUE if the lock would block
@return string
@throws Exception\RuntimeException
Read a complete file