You are here

protected function FileProfilerStorage::readLineFromFile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php \Symfony\Component\HttpKernel\Profiler\FileProfilerStorage::readLineFromFile()

Reads a line in the file, backward.

This function automatically skips the empty lines and do not include the line return in result value.

Parameters

resource $file The file resource, with the pointer placed at the end of the line to read:

Return value

mixed A string representing the line or null if beginning of file is reached

1 call to FileProfilerStorage::readLineFromFile()
FileProfilerStorage::find in vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php
Finds profiler tokens for the given criteria.

File

vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php, line 217

Class

FileProfilerStorage
Storage for profiler using files.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

protected function readLineFromFile($file) {
  $line = '';
  $position = ftell($file);
  if (0 === $position) {
    return;
  }
  while (true) {
    $chunkSize = min($position, 1024);
    $position -= $chunkSize;
    fseek($file, $position);
    if (0 === $chunkSize) {

      // bof reached
      break;
    }
    $buffer = fread($file, $chunkSize);
    if (false === ($upTo = strrpos($buffer, "\n"))) {
      $line = $buffer . $line;
      continue;
    }
    $position += $upTo;
    $line = substr($buffer, $upTo + 1) . $line;
    fseek($file, max(0, $position), SEEK_SET);
    if ('' !== $line) {
      break;
    }
  }
  return '' === $line ? null : $line;
}