Read file by handle and verify if content is expired

@param  resource    $handle file handle
@param  string      $file   file path
@return false|array false or file content array
2134
protected function readAndVerify($handle, $file)
    {
        // Read all content
        $content = fread($handle, filesize($file));
        $content = @unserialize($content);

        // Check if content is valid
        if ($content && is_array($content) && time() < $content[0]) {
            return $content;
        } else {
            return false;
        }
    }
652918
public function store(string $fileName, $handle): ImageDriver
    {
        $this->lastStoredFileName = $fileName;
        $this->lastStoredHandle   = $handle;
        return $this;
    }
1362107
public function read(string $key)
    {
        $file = $this->cacheFile($key);

        if (is_file($file)) {
            // Cache exists
            $data = include $file;
            $expire = (int)$data['ttl'];
            if ($expire === 0 || time() < $expire) {
                return unserialize($data['data']);
            }
            unlink($file);
        }

        return false;
    }
29003
function _close_handle($handle)
    {
        if (!$this->_send_sftp_packet(NET_SFTP_CLOSE, pack('Na*', strlen($handle), $handle))) {
            return false;
        }

        // "The client MUST release all resources associated with the handle regardless of the status."
        //  -- http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.1.3
        $response = $this->_get_sftp_packet();
        if ($this->packet_type != NET_SFTP_STATUS) {
            user_error('Expected SSH_FXP_STATUS');
            return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Nstatus', $this->_string_shift($response, 4)));
        if ($status != NET_SFTP_STATUS_OK) {
            $this->_logError($response, $status);
            return false;
        }

        return true;
    }
725018
public function readFile(string $file_name)
    {
        // yaml_read_file does not support stream wrappers
        $file_handle = @fopen($file_name, "r");
        if (!is_resource($file_handle))
            throw new IOException("Failed to read file: " . $file_name);
        return $this->readFileHandle($file_handle);
    }
613781
public function write($handle, string $data, $length = null) : int
    {
        $bytesWritten = is_int($length) ? fwrite($handle, $data, $length) : fwrite($handle, $data);

        if (false === $bytesWritten) {
            throw new FileException('Cannot write to a file.');
        }

        return $bytesWritten;
    }
519386
public static function isFileReadable($file)
    {
        $result = false;

        if (!file_exists($file)) {
            return $result;
        }
        if (!is_file($file)) {
            return $result;
        }
        if (!is_readable($file)) {
            return $result;
        }

        $result = true;

        return $result;
    }
196335
public function read($file_name, $content = '')
    {
        if (!is_file($file_name)) {
            return false;
        }

        return file_get_contents($file_name, $content, LOCK_EX);
    }
629138
private function tryReadFile($path) {
        if (!file_exists($path)) {
            return false;
        }

        $interval = 100000;
        $totalTime = 0;

        while (($result = file_get_contents($path)) === false) {
            if ($totalTime >= $this->accessTime) {
                return false;
            }

            usleep($interval);

            $totalTime += $interval;
        }

        return $result;
    }
1072530
protected static function ttlWithLock($handle): int {
		$content = '';
		while (!feof($handle)) {//循环读取，直至读取完整个文件
			$content .= fread($handle, 1024);
		}
		$expire    = (int)substr($content, 8, 12);
		$filemtime = (int)substr($content, 20, 12);
		$time      = static::getExpire($filemtime, $expire);
		if ($time === 0) {
			return -2;
		}
		return $time;
	}
1175681
public static function read($file)
    {
        if (!is_readable($file)) {
            return;
        }
        $data = @file_get_contents($file);
        if ($data === false) {
            return;
        }
        $value = @unserialize($data);
        if ($value === false) {
            return;
        }

        return $value;
    }
1156630
public static function writeAndRead($handle = 0, $command = '', $arguments = array()) {
        $buffer = self::parseCommand($command, $arguments);
        self::_writeToServer($handle, $buffer);
        return self::read($handle);
    }
937747
protected function copyResultFile($handler, $file)
    {
        if (!is_file($file)) {
            throw new \OutOfBoundsException("Result file $file is not readable");
        }

        $extension = 'xml';
        if (preg_match('(\.([a-z]+)$)', $file, $match)) {
            $extension = $match[1];
        }

        copy($file, $this->targetDir . '/' . $handler . '.' . $extension);

        return "$handler.$extension";
    }
542798
public function fetch($key)
    {
        $file_name = $this->getFilePath($key);
        if (!\file_exists($file_name) || !\is_readable($file_name)) {
            return false;
        } else {
            $h = \fopen($file_name, 'r');
            //lock file
            \flock($h, LOCK_SH);
        }

        $data = \file_get_contents($file_name);

        //release lock
        \fclose($h);

        $data = @\unserialize($data);

        //check to see if it expired
        if ($data && ($data[0] == 0 || time() <= $data[0])) {
            return $data[1];
        } else {
            $this->delete($key);
            return false;
        }

        return $data[1];
    }
757927
public function get($key)
    {
        $filename = $this->_filename($key);
        if (!file_exists($filename)) {
            return false;
        }

        $tmp_value = file_get_contents($filename);
        $expire    = (int) substr($tmp_value, 13, 24);

        // echo time()."<br />\n";
        // echo $expire."<br />\n";
        // echo substr($tmp_value,23);exit;

        if ($expire != 0 && time() < $expire) {
            return unserialize(substr($tmp_value, 23));
        } else {
            return false;
        }
    }
711707
protected function writeAndRelease($handle, $content, $rewrite = false)
    {
        $rewrite && rewind($handle) && ftruncate($handle, 0);
        $result = fwrite($handle, $content);
        flock($handle, LOCK_UN);
        fclose($handle);
        return (bool) $result;
    }
610163
private function read_file($file)
  {
    $handler = fopen($file, "r");
    $file_content = fread($handler, filesize($file));
    fclose($handler);

    return $file_content;
  }