<?
$begin = getmicrotime();
error_reporting(E_ALL);
$mem_lim=ini_get("memory_limit");
$num_iterations=$mem_lim-1;
// increase memory limit
#ini_set("memory_limit", "256M");
ini_set("max_execution_time", "60");
echo "memory limit set to $mem_lim<br>";
echo "max_execution_time set to " . ini_get("max_execution_time") . "<br>";
echo "Building very long string ... <br>";
flush();
$array = array();
for ($i = 1; $i <= $num_iterations; $i++) {
echo "Adding 1M data ... ";
add($array);
echo "[OK] Total: $i Mb<br>";
}
#echo "<br>[OK] Total: $i Mb<br>";
$end = getmicrotime();
echo "Execution time: "; echo $end - $begin;
function getmicrotime() // {{{
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function add(&$array)
{
$array[] = $str = str_repeat("*", 1024*1024);
return $array;
}
?>
Adding 1M data ... [OK] Total: 152 Mb
Adding 1M data ... [OK] Total: 153 Mb
Adding 1M data ...
Fatal error: Out of memory (allocated 200802304) (tried to allocate 1048577 bytes) in /var/www/vhosts/..../httpdocs/2.php on line 32