Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a small-ish class that makes it easy to read a number of characters from the back of a large file w/o overloading memory. The test setting lets you see it in action cannibalizing itself.</p> <pre><code>BigFile.php &lt;?php $run_test = true; $test_file = 'BigFile.php'; class BigFile { private $file_handle; /** * * Load the file from a filepath * @param string $path_to_file * @throws Exception if path cannot be read from */ public function __construct( $path_to_log ) { if( is_readable($path_to_log) ) { $this-&gt;file_handle = fopen( $path_to_log, 'r'); } else { throw new Exception("The file path to the file is not valid"); } } /** * * 'Finish your breakfast' - Jay Z's homme Strict */ public function __destruct() { fclose($this-&gt;file_handle); } /** * * Returns a number of characters from the end of a file w/o loading the entire file into memory * @param integer $number_of_characters_to_get * @return string $characters */ public function getFromEnd( $number_of_characters_to_get ) { $offset = -1*$number_of_characters_to_get; $text = ""; fseek( $this-&gt;file_handle, $offset , SEEK_END); while(!feof($this-&gt;file_handle)) { $text .= fgets($this-&gt;file_handle); } return $text; } } if( $run_test ) { $number_of_characters_to_get = 100000; $bf = new BigFile($test_file); $text = $bf-&gt;getFromEnd( $number_of_characters_to_get ); echo "$test_file has the following $number_of_characters_to_get characters at the end: &lt;br/&gt; &lt;pre&gt;$text&lt;/pre&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload