Created
November 16, 2020 13:46
-
-
Save BurakBoz/1ce46001719d92c8beefcaead731c318 to your computer and use it in GitHub Desktop.
PHP Function: Read Lines Memory Efficiently
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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