1--TEST-- 2Bug #81659 (stream_get_contents() may unnecessarily overallocate) 3--FILE-- 4<?php 5$stream = fopen(__DIR__ . "/81659.txt", "w+"); 6 7for ($i = 0; $i < 1024; $i++) { 8 fwrite($stream, str_repeat("*", 1024)); 9} 10 11fseek($stream, 1023 * 1024); 12 13$m0 = memory_get_peak_usage(); 14var_dump(strlen(stream_get_contents($stream))); 15$m1 = memory_get_peak_usage(); 16var_dump($m1 < $m0 + 512 * 1024); 17?> 18--CLEAN-- 19<?php 20@unlink(__DIR__ . "/81659.txt"); 21?> 22--EXPECT-- 23int(1024) 24bool(true) 25