Beginner LevelPHP 8+
How do you inspect PHP environment extensions, memory limits, and configuration settings using phpinfo() and ini_get()?
❓ Interview Prompt: Explain runtime PHP environment inspection, checking enabled extensions (extension_loaded), memory limits, and phpinfo() security risks.
Inspecting runtime environment configurations ensures scripts have necessary memory and PHP binary extensions available:
Environment Inspection Utilities:
•
'ini_get("setting")': Reads active 'php.ini' configuration values (e.g. 'ini_get("memory_limit")').
•
'extension_loaded("ext")': Checks if a binary extension is installed and active (e.g. 'extension_loaded("pdo_mysql")').
•
'phpversion()': Returns current running PHP version string (e.g. '"8.3.4"').
•
'phpinfo()': Outputs a complete HTML page detailing PHP build configurations, loaded modules, and environment variables.
Security Warning:
NEVER expose 'phpinfo()' on public production URLs! Hackers use 'phpinfo()' outputs to discover exact OS versions, loaded modules, and internal file paths for targeted exploits.
Code Implementation Example
php
<?php
// Verify required extensions and memory limits at application startup
if (!extension_loaded('pdo_mysql')) {
die("Application requires pdo_mysql extension!");
}
$memoryLimit = ini_get('memory_limit');
$phpVersion = phpversion();
echo "Running PHP {$phpVersion} with memory limit: {$memoryLimit}";💡Programmatically inspecting PHP version, loaded extensions, and memory limit.
🎯 Interview Key Takeaway
Use ini_get() and extension_loaded() to verify runtime requirements. Never expose phpinfo() on public production servers.
#phpinfo#ini_get#Environment#Security#Beginner
Back to all PHP 8+ Questions→