PHP 8.5.0 Alpha 1 available for testing

Voting

: min(nine, two)?
(Example: nine)

The Note You're Voting On

miami at blackcrystal dot net
10 years ago
Sometimes, we need all memory to run our task, we do ini_set('memory_limit', -1 ), or maximum value we have.

To avoid stuck of server on long and memory consuming tasks, i wrote this check. This is not the same as memory_get_usage() do, but more. It shows virtual memory amount, taken by your process. In percents.

<?php
function getVirtualMemoryTaken()
{
$pid = getmypid();
$a = `ps -p $pid v | awk 'END{print $9}'`;
return
$a*1;
}
?>

It works only in linux, tested in Ubuntu 14.

<?php
$a
= ' ';
do {
$a .= $a . $a; }
while (
getVirtualMemoryTaken() < 20 );
?>

<< Back to user notes page

To Top