|
14 | 14 |
|
15 | 15 | ini_set('memory_limit', $memoryLimit . "M");
|
16 | 16 |
|
| 17 | +// Force output flushing, like in CLI |
| 18 | +// May help with proxy-pass apache-nginx |
| 19 | +@ini_set('output_buffering', 0); |
| 20 | +@ini_set('implicit_flush', 1); |
| 21 | +ob_implicit_flush(1); |
| 22 | +// Special for nginx |
| 23 | +header('X-Accel-Buffering: no'); |
| 24 | + |
17 | 25 | function convert($size)
|
18 | 26 | {
|
19 | 27 | $unit = array('b', 'kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb');
|
20 | 28 | return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
|
21 | 29 | }
|
22 | 30 |
|
| 31 | +function shutDownFunction() { |
| 32 | + $error = error_get_last(); |
| 33 | + if ($error['type'] === E_ERROR) { |
| 34 | + echo '</pre>'; |
| 35 | + } |
| 36 | +} |
| 37 | +register_shutdown_function('shutDownFunction'); |
| 38 | + |
23 | 39 | $l = 1024 * 1024; // 1 Mb
|
24 | 40 | $s = '';
|
25 | 41 |
|
| 42 | +echo '<pre>'; |
26 | 43 | for ($i = 0; $i < $memoryLimit; $i++) {
|
27 | | - $s .= str_pad('a', $l); |
| 44 | + try { |
| 45 | + $s .= str_pad('a', $l); |
| 46 | + } catch (Exception $e) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + |
28 | 50 | echo convert(memory_get_peak_usage(true)) . ' | ' . convert(memory_get_usage()) . ' | ' . convert(mb_strlen($s)) . PHP_EOL;
|
29 | 51 | }
|
0 commit comments