<?php
/**
 * PHP Limits Checker
 * Check current PHP configuration for export functionality
 */

header('Content-Type: text/plain');

echo "=== PHP CONFIGURATION CHECK ===\n\n";

echo "Memory Limit: " . ini_get('memory_limit') . "\n";
echo "Max Execution Time: " . ini_get('max_execution_time') . " seconds\n";
echo "Max Input Time: " . ini_get('max_input_time') . " seconds\n";
echo "Post Max Size: " . ini_get('post_max_size') . "\n";
echo "Upload Max Filesize: " . ini_get('upload_max_filesize') . "\n";
echo "Max Input Vars: " . ini_get('max_input_vars') . "\n";
echo "\n";

echo "Output Buffering: " . (ini_get('output_buffering') ? 'Enabled (' . ini_get('output_buffering') . ')' : 'Disabled') . "\n";
echo "Display Errors: " . (ini_get('display_errors') ? 'On' : 'Off') . "\n";
echo "Error Reporting: " . ini_get('error_reporting') . "\n";
echo "\n";

echo "PHP Version: " . PHP_VERSION . "\n";
echo "Server API: " . PHP_SAPI . "\n";
echo "\n";

echo "=== MEMORY INFO ===\n";
echo "Current Memory Usage: " . round(memory_get_usage() / 1024 / 1024, 2) . " MB\n";
echo "Peak Memory Usage: " . round(memory_get_peak_usage() / 1024 / 1024, 2) . " MB\n";
echo "\n";

echo "=== RECOMMENDATIONS ===\n";
$memory_limit = ini_get('memory_limit');
if (preg_match('/(\d+)M/', $memory_limit, $matches)) {
    $mb = (int)$matches[1];
    if ($mb < 2048) {
        echo "⚠️ Memory limit is {$memory_limit}. Recommended: 2048M or higher for large exports.\n";
    } else {
        echo "✓ Memory limit is adequate: {$memory_limit}\n";
    }
}

$max_exec = ini_get('max_execution_time');
if ($max_exec != 0 && $max_exec < 600) {
    echo "⚠️ Max execution time is {$max_exec}s. Recommended: 0 (unlimited) for large exports.\n";
} else {
    echo "✓ Max execution time is adequate: " . ($max_exec == 0 ? 'unlimited' : $max_exec . 's') . "\n";
}

echo "\n=== ACCESS THIS FILE ===\n";
echo "URL: " . (isset($_SERVER['HTTPS']) ? 'https' : 'http') . "://{$_SERVER['HTTP_HOST']}/check_limits.php\n";
