Tag Archives: http

Tutorial for custom maintenance mode in WordPress

Maintenance mode in WordPress

Maintenance mode is the “be right back” state of your website.  You should use it any time you are changing the WordPress code or making anything else with a non-zero possibility to fail and affect a user experience.

You’ve probably noticed that WordPress is actually turning the built-in maintenance mode while upgrading the WP core, or adding new plugins.

In this article, you’ll learn how it works, how to turn the maintenance mode on manually, and how to make it look better.

How the built-in maintenance mode works

When you click the “upgrade WordPress” button,  Wordpress is inserting the .maintenance php file into the site’s root directory with $upgrading variable set to time().

Wordpress maintenance mode function

Every single time someone enters your site, WordPress is looking for this particular file and if it exists, WordPress is comparing the $upgrading variable with the time() value. If the difference is less than 600 seconds (10 minutes), the maintenance mode function is looking for a custom maintenance.php inside wp-content directory.

If it exists, WordPress loads that file and exits the compilation process.

If not, the maintenance function compiles the built-in maintenance landing page and ends with the compilation process. What’s important, WordPress handles the maintenance mode well with a proper http code sending to a user.

Find out why the proper http code is important.

How to make a custom maintenance mode landing page?

To make a custom maintenance mode landing page, you just need to make your own php script and save it into wp-content directory as maintenance.php file. Every time your site is in the maintenance mode, WordPress will look for this file and compile it, ignoring the built-in landing page.

To make it easier for you, we’ve made an example script. You can grab it from our GitHub repository and customise it any way you like.

How to turn on the maintenance mode manually?

If you would like to turn on the maintenance mode manually, without any plugin you just need to insert the .maintenance file into your WordPress main folder.

We made the file for you, extending it with an IP white list and secret key white list support. You can grab it from our GitHub repo as well as the maintenance.php example file.

 

How machines talk to each other

A guide for human beings – HTTP codes

AgentSlug.com is meant to be so simple that anyone can use it without any trouble.

However, there are some kind of technical terms you should actually know to understand what’s going on with your website.

This article is not for technical people, it simplifies many complicated issues.

How does it work and why it matters?

Imagine you are looking for some company document. You know it probably exists, but you don’t really know where exactly.  You just know its name.  Let’s say it’s a Holiday Funding Request Form*

First thing you do is you call your colleague who works here longer than you and knows everyone. He tells you that you should call a guy from HR department. The HR guy redirects you to Finances. You go there, and you are told to be back in couple of minutes, because they are doing some maintenance and can’t serve you now.

After a couple of minutes you go back and get the proper form.

Machines works almost the same way. URLs are something like names.  Unified names with whole addresses.

When you type an URL and hit the enter key, your browser sends a request to a DNS server. DNS is you friend who knows everyone or knows people who know people. DNS routes your browser to a proper server by resolving the domain name to a related IP number.  Sometimes the first DNS knows the name and knows the IP. Sometimes it has to ask other DNS .

Then your request is routed to a proper server by the IP address. If the server is up and responding, it should send some response to your browser.

When the URL matches any document on server, response should contain HTTP 200 “OK” code. It means “everything is fine, here’s what you are looking for”.

If the server is down for maintenance, it should send you an HTTP 503 response. Translation of this code to the human language is “sorry, we have some issue over here, come back later”.

If the server can’t find the document, but knows where you should go to find it, it will redirect you (your browser) by sending an HTTP 301 code which means “there’s nothing here, the resources were moved to another location, you should go somewhere else”.

So, why does it matter?

Machines communicate in a human-like way. They were made by humans and they are similar to humans in many dimensions.

scuba_maintenance_modeYour server should respond properly. Imagine you are asking the finance guy for a Holiday Form. He tells you “OK, here you go” and doesn’t give it to you. It would be weird, right?

The same story is when machines speak to each other.  We noticed that some websites in the maintenance mode, send HTTP 200 code with a nice “be right back” landing page. If one of the Google indexing crawlers came there during this pseudo-maintenance mode, it would identify the landing page as a regular page and switch the indexed page with the maintenance notice.

Learn more about http codes and their meanings.

* In many EU countries, companies can participate in employees’ vacation.