Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a60eeac

Browse files
committed
наработки
1 parent d4ba20f commit a60eeac

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

‎memory.php‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,38 @@
1414

1515
ini_set('memory_limit', $memoryLimit . "M");
1616

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+
1725
function convert($size)
1826
{
1927
$unit = array('b', 'kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb');
2028
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
2129
}
2230

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+
2339
$l = 1024 * 1024; // 1 Mb
2440
$s = '';
2541

42+
echo '<pre>';
2643
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+
2850
echo convert(memory_get_peak_usage(true)) . ' | ' . convert(memory_get_usage()) . ' | ' . convert(mb_strlen($s)) . PHP_EOL;
2951
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /