Last active
September 5, 2017 05:53
-
-
Save ducfilan/1ecbfbdd9a7126eec9c5e60aa923db7f to your computer and use it in GitHub Desktop.
Handle huge CSV file
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
| function file_get_contents_chunked($file, $chunk_size, $args, $callback) { | |
| try { | |
| $handle = fopen($file, "r"); | |
| $i = 0; | |
| while (!feof($handle)) | |
| { | |
| call_user_func_array($callback,array(fread($handle,$chunk_size),&$handle,$i, $args)); | |
| $i++; | |
| } | |
| fclose($handle); | |
| } | |
| catch(Exception $e) | |
| { | |
| trigger_error("file_get_contents_chunked: " . $e->getMessage(),E_USER_NOTICE); | |
| return false; | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment