Repository
https://github.com/zghafari/keep-my-site-up
Preface
Ever hosted a website for yourself or your client and noticed that it was extremely slow loading the first time but faster in subsequent loads?
It appears that the servers go into a “sleep” mode after a certain period of time, presumably 5 minutes after experimentation. After this period of time the web pages load faster on any device until it is inactive again.
By going into a sleep mode the hosting provider is able to save money but costs you visitors as they may just bounce off your website.
Fix
There are multiple ways to fix this.
The first way to fix this is to just upgrade to a higher hosting plan, it’ll cost you more money but you wouldn’t need to worry about this problem anymore.
The second way is to write a small script that keeps your site refreshed at 4 minute cycles. Something like a Raspberry pi / pi zero would work perfectly for this type of task. If you don’t want to go through the trouble of setting up a raspberry pi you can just run a script locally on your desktop.
I should say that your hosting provider may not like this that at all and if done too frequently it has the potential to trigger a DDOS alarm. However 1 call every 5 minutes should be perfectly fine.
Curl-Format
The curl-format.txt provides information on your http transaction timings, this is what will be outputted by the curl
command.
time_namelookup: %{time_namelookup}\n time_connect: %{time_connect}\n time_appconnect: %{time_appconnect}\n time_pretransfer: %{time_pretransfer}\n time_redirect: %{time_redirect}\n time_starttransfer: %{time_starttransfer}\n ----------\n time_total: %{time_total}\n
Change the variable IPADDRESS
to the website url you would like to use. INTERVAL
is set to 240 seconds or 4 minutes.
Mac – Bash
IPADDRESS="aws-cloud.guru" INTERVAL=240 echo "IP ADDRESS:" $IPADDRESS echo "TIMEOUT:" $INTERVAL while true do curl -w "@curl-format.txt" -o NUL -s $IPADDRESS echo "Waiting" $INTERVAL "Seconds" sleep $INTERVAL done
Windows – Batch
@ECHO OFF set IPADDRESS=yoursitename.com set INTERVAL=240 :PINGINTERVAL curl -w "@%~dp0curl-format.txt" -o NUL -s %IPADDRESS% timeout %INTERVAL% GOTO PINGINTERVAL