Skip to content

Instantly share code, notes, and snippets.

@BurakBoz
Created November 16, 2020 13:46
Show Gist options
  • Save BurakBoz/1ce46001719d92c8beefcaead731c318 to your computer and use it in GitHub Desktop.
Save BurakBoz/1ce46001719d92c8beefcaead731c318 to your computer and use it in GitHub Desktop.
PHP Function: Read Lines Memory Efficiently
<?php
/**
* Read Lines Memory Efficiently
* @param $file
* @param callable $callable
* @return bool
*/
function read_lines_me($file, callable $callable)
{
$handle = @fopen($file, "r");
if(!$handle) return false;
while (($line = fgets($handle)) !== false) $callable($line);
@fclose($handle);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment