Created
November 10, 2017 04:34
-
-
Save mix5003/3d27a3a401f0f1415f57828c3bef9295 to your computer and use it in GitHub Desktop.
fread make a var use memory equals to buffer length. even if it has only few bytes
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 | |
| ini_set('memory_limit', '256M'); | |
| // create file | |
| @mkdir('tmp_file'); | |
| for($i=0;$i<300;$i++){ | |
| file_put_contents("tmp_file/{$i}.txt", $i); | |
| } | |
| // read file | |
| $data = []; | |
| for($i=0;$i<300;$i++){ | |
| $fp = fopen("tmp_file/{$i}.txt", "r"); | |
| $data[$i] = fread($fp, 1024 * 1024); | |
| fclose($fp); | |
| echo strlen($data[$i])." ".memory_get_usage()."\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment