What are the best practices for implementing a maintenance mode in PHP using a config file?

Implementing a maintenance mode in PHP using a config file allows you to easily enable or disable maintenance mode without modifying the code. By storing the maintenance mode status in a config file, you can control the behavior of your application during maintenance periods.

// config.php
<?php
return [
    'maintenance_mode' => true, // Set to true to enable maintenance mode
];

// index.php
<?php
$config = require 'config.php';

if ($config['maintenance_mode']) {
    http_response_code(503);
    include 'maintenance.php';
    exit;
}

// maintenance.php
<!DOCTYPE html>
<html>
<head>
    <title>Maintenance Mode</title>
</head>
<body>
    <h1>Site Under Maintenance</h1>
    <p>We apologize for the inconvenience. Please check back later.</p>
</body>
</html>