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>
Related Questions
- What are some best practices for creating a PHP script for a daily task scheduler?
- How can one retrieve the name of a specific column, such as the third column, in PDO or mysqli?
- How can unexpected values from Google Analytics cookies end up in the $_REQUEST array if the website does not use Google Analytics or cookies?