Skip to content

Instantly share code, notes, and snippets.

@shevron
Forked from anonymous/test.php
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shevron/66737e9f07a6ac6464d8 to your computer and use it in GitHub Desktop.
Save shevron/66737e9f07a6ac6464d8 to your computer and use it in GitHub Desktop.
A better way to write to /dev/null
<?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