Skip to content

Instantly share code, notes, and snippets.

@ducfilan
Last active September 5, 2017 05:53
Show Gist options
  • Select an option

  • Save ducfilan/1ecbfbdd9a7126eec9c5e60aa923db7f to your computer and use it in GitHub Desktop.

Select an option

Save ducfilan/1ecbfbdd9a7126eec9c5e60aa923db7f to your computer and use it in GitHub Desktop.
Handle huge CSV file
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