-
-
Save shevron/66737e9f07a6ac6464d8 to your computer and use it in GitHub Desktop.
A better way to write to /dev/null
This file contains 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 | |
// Get 10mb of data from /dev/zero | |
$infp = fopen('/dev/zero', 'r'); | |
$data = fread($infp, 1024 * 1024 * 10); | |
fclose($infp); | |
write_data($data); | |
echo "Peak memory usage: ", number_format(memory_get_peak_usage()), " bytes\n"; | |
/** | |
* Bad example of how to write some data to /dev/null | |
*/ | |
function write_data($data) | |
{ | |
$outfp = fopen('/dev/null', 'w'); | |
fwrite($outfp, $data); | |
fwrite($outfp, "\n"); | |
fclose($outfp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment