<?php
/**
* Server Health Check & PHP Info Script
* Digunakan untuk memeriksa kesehatan server lokal Laragon setelah terjadi crash.
*/
// 1. Ambil Data Penggunaan Memori & Disk Windows
$disk_free = disk_free_space("C:");
$disk_total = disk_total_space("C:");
$disk_used = $disk_total - $disk_free;
$disk_percentage = round(($disk_used / $disk_total) * 100, 2);
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}
// 2. Periksa Status Ekstensi Penting
$extensions = [
'ionCube Loader' => extension_loaded('ionCube Loader'),
'PDO MySQL' => extension_loaded('pdo_mysql'),
'OpenSSL' => extension_loaded('openssl'),
'MBString' => extension_loaded('mbstring'),
'GD Graphics' => extension_loaded('gd'),
'cURL' => extension_loaded('curl'),
'Zip' => extension_loaded('zip')
];
// 3. Tampilan Interface HTML
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Laragon Server Health Status</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f4f6f9; color: #333; margin: 0; padding: 20px; }
.container { max-width: 1000px; margin: 0 auto; background: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
h1, h2 { color: #2c3e50; border-bottom: 2px solid #ecf0f1; padding-bottom: 10px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px; }
@media(max-width: 768px) { .grid { grid-template-columns: 1fr; } }
.card { background: #fafbfc; border: 1px solid #e1e4e8; padding: 15px; border-radius: 6px; }
.status { font-weight: bold; padding: 4px 8px; border-radius: 4px; display: inline-block; }
.status.ok { background: #d4edda; color: #155724; }
.status.fail { background: #f8d7da; color: #721c24; }
.phpinfo-wrapper { margin-top: 40px; border-top: 3px solid #3498db; padding-top: 20px; }
/* Reset gaya phpinfo agar rapi di dalam container */
.phpinfo-wrapper table { width: 100% !important; border-collapse: collapse !important; margin-bottom: 20px !important; font-size: 14px; }
.phpinfo-wrapper th, .phpinfo-wrapper td { border: 1px solid #ddd !important; padding: 8px !important; text-align: left !important; }
.phpinfo-wrapper tr:nth-child(even) { background-color: #f9f9f9; }
.phpinfo-wrapper .h { background-color: #3498db !important; color: white !important; font-weight: bold; }
.phpinfo-wrapper .e { background-color: #f2f2f2; font-weight: bold; width: 30%; }
</style>
</head>
<body>
<div class="container">
<h1> diagnostic Status Server Laragon</h1>
<p>Gunakan informasi di bawah ini untuk melihat apakah lingkungan PHP Anda rusak setelah laptop crash.</p>
<div class="grid">
<div class="card">
<h2>Kapasitas Harddisk (C:)</h2>
<p><strong>Total Ruang:</strong> <?php echo formatBytes($disk_total); ?></p>
<p><strong>Tersisa:</strong> <?php echo formatBytes($disk_free); ?></p>
<p><strong>Terpakai:</strong> <?php echo formatBytes($disk_used); ?> (<?php echo $disk_percentage; ?>%)</p>
<?php if ($disk_free < 5 * 1024 * 1024 * 1024): ?>
<span class="status fail">Peringatan: Disk Hampir Penuh!</span>
<?php else: ?>
<span class="status ok">Penyimpanan Aman</span>
<?php endif; ?>
</div>
<div class="card">
<h2>Status Ekstensi Penting</h2>
<ul style="list-style: none; padding: 0;">
<?php foreach ($extensions as $name => $loaded): ?>
<li style="margin-bottom: 8px; display: flex; justify-content: space-between;">
<span><?php echo $name; ?>:</span>
<span class="status <?php echo $loaded ? 'ok' : 'fail'; ?>">
<?php echo $loaded ? 'Aktif' : 'Tidak Aktif / Error'; ?>
</span>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="card" style="margin-bottom: 30px;">
<h2>Sistem Inti PHP</h2>
<p><strong>Versi PHP:</strong> <?php echo PHP_VERSION; ?></p>
<p><strong>Sistem Operasi:</strong> <?php echo PHP_OS_FAMILY . ' (' . php_uname('s') . ')'; ?></p>
<p><strong>File php.ini Aktif:</strong> <?php echo php_ini_loaded_file(); ?></p>
<p><strong>Batas Memori (Memory Limit):</strong> <?php echo ini_get('memory_limit'); ?></p>
</div>
<div class="phpinfo-wrapper">
<h2>Detail Lengkap PHP Info</h2>
<?php
// Mengambil output phpinfo() dan membersihkan tag html/body bawaannya agar menyatu dengan css di atas
ob_start();
phpinfo();
$pinfo = ob_get_contents();
ob_end_clean();
$pinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $pinfo);
echo $pinfo;
?>
</div>
</div>
</body>
</html>