<?php
session_start();
ini_set('max_execution_time', 0); // Disable time limit for stress test
ini_set('memory_limit', '-1'); // Set memory limit to unlimited
// Check if session variable 'memory' exists, if not, initialize it
if (!isset($_SESSION['memory'])) {
$_SESSION['memory'] = 0;
}
echo "Starting memory stress test...\n";
// Simulate memory-intensive task by creating large arrays
$memoryHog = [];
// Increase memory usage each time the page is hit
$memoryIncrement = 1024 * 1024; // 1MB per hit
$memoryTarget = $_SESSION['memory'] + $memoryIncrement;
while ($_SESSION['memory'] < $memoryTarget) {
// Add large arrays to memory
$memoryHog[] = str_repeat('A', 1024 * 1024); // Add 1MB strings
$_SESSION['memory'] += $memoryIncrement; // Track total memory used
echo "Allocated " . $_SESSION['memory'] / (1024 * 1024) . "MB of memory...\n";
flush(); // Flush the output to the browser immediately
sleep(1); // Sleep to prevent a complete hang
}
echo "Memory stress test completed.";
$_SESSION['memory'] = 0; // Reset memory after completion
?>