Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Refresh maintenance mode page automatically in Laravel 8.x

Laravel has this cool feature using which you can put your website in maintenance mode. To do so, all you will need to do is run the following command.

$ php artisan down

When you put your website in maintenance mode, it will render the following page if you try to access your website.

Now, this is fine but in an ideal scenario, you wouldn’t want to put your website in maintenance mode for a long period. You might want to let the user know that the site is now up when you run php artisan up.

The simplest way using which you can do this is by refreshing the page at a regular interval. How would you do that?

The --refresh option

The recent release of Laravel 8.x has introduced this feature which lets you do just the same.

To make this work, all you will need to do is passing in a --refresh option to the php artisan down command. You need to assign an integer value to the option which acts as a number of seconds. Take the following for example.

$ php artisan down --refresh=60

As you can tell, we passed in 60 to the --refresh option. When doing so, a Refresh HTTP header will be sent with maintenance mode responses forcing the browser to refresh after 60 seconds.

And this way users won’t have to refresh the website themselves to check whether it’s up and running now or not.

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?