How to get up-to-date weather data?

by | May 16, 2017

Before being a plugin that displays weather in widgets, or directly in pages or posts, Weather Station is primarily a tool for collecting and sharing weather data. The quality of the calculated meteorological indices and the freshness of the displayed or shared values depend directly on the reliability of this collection. So to not let you be surprised one day by obsolete data, I offer you a dive into the heart of WordPress and Weather Station and introduces you several methods to optimize the collection and sharing of your stations data.

Weather Station can schedule data collection every 30 minutes, 20 minutes, 15 minutes, 10 minutes, or 5 minutes (and even every 2 minutes for certain stations types, starting with version 3.3). In addition to this data collection, Weather Station also has the ability to share its data with meteorological services at a frequency of 20 minutes, 10 minutes or 6 minutes (and 2 minutes, for Weather Underground, starting with version 3.3).

Obviously, this recurrent collection and sharing activity must be as regular as possible to allow a “fluid” operation of the plugin and allow the handling of the most recent data.

The WordPress task scheduler

For all of these collection and sharing operations to be performed, Weather Station relies on the WordPress built-in task scheduler. This task scheduler, which is launched by a system bearing the sweet name of WordPress Cron, is the system that already allows you to schedule your backups and the publication of a post at a given time, update your extensions or themes, etc. As this task scheduler is inseparable from WordPress, it is used, tested and maintained on hundreds of millions of websites, and this made it an essential choice of architecture for Weather Station.

Sadly, this task scheduler suffers some kinks …

The first and most important of these flaws is that this scheduler only works correctly on a web site that has traffic. Indeed, it is triggered only when a page is visited and a task is to be launched. This means that if there is a task to be launched every five minutes and the site is not visited for about 15 minutes, instead of being executed 3 times, this task will be executed only one time.

And that does not stop there, the list of flaws is long

Fortunately, there are several simple methods to make this task scheduler quite performing and thus offer your site up-to-date weather data. And incidentally accelerate and make efficient all functions and plugins using scheduled tasks.

A web cron

The method described here is to delegate the launch of the task scheduler to an online service. To do this, you can use a free or paid specialized service or a “generic” service (like a monitoring tool), also free or paid. Note that if the free services are obviously interesting, they will not allow you, for some, to benefit from the innovations introduced by the version 3.3 of Weather Station. So choose your service provider according to your actual needs.

To illustrate this method, we will take as an example cron-job.org which is a free specialized service offering everything you need to use ultra-responsive WordPress task scheduler.

Here’s how:

1 – disable WordPress cron
This is done simply by adding a line to your wp-config.php file:

define('DISABLE_WP_CRON', 'true');

 
2 – create an account on cron-job.org

3 – add a cronjob in cron-job.org
Click on the “Cronjobs” button (top left) and then on “Create cronjob”. The page that appears allows you to set your new cronjob:

Creating a cron job with cron-job.org

For the address, enter the URL of your WordPress site, followed by wp-cron.php. For the frequency, I suggest you “every 5 minute(s)” or better “every 2 minute(s)” if you use the normal mode of Weather Station. On the other hand, if you are using fast mode (available from Weather Station version 3.3), choose “every 1 minute(s)”.

And now, cron-job.org will launch the WordPress task scheduler for your site at the selected frequency. Your site and your weather data tell you thanks!

A true “system” cron

This second method, more precise (and probably more complex to implement) is reserved for those of you who have a console access to their server or a cPanel type access allowing to set the cron table directly on the server. It consists, this time, to ask the operating system of the server to initiate the WordPress task scheduler.

Here’s how to do it with console access:

1 – disable WordPress cron
Again, this is done simply by adding a line to your wp-config.php file:

define('DISABLE_WP_CRON', 'true');

 
2 – connect to your server console

3 – edit your crontab file

crontab -e

 
Insert the following line that best fits your case, replacing $WEBPATH with the actual path of the directory where WordPress is installed.

# using php
* * * * * php $WEBPATH/wp-cron.php > /dev/null 2>&1

# using curl
* * * * * curl http://example.com/wp-cron.php > /dev/null 2>&1

# using wget
* * * * * wget -O - -q -t 1 http://example.com/wp-cron.php > /dev/null 2>&1

 
With, for example:

WEBPATH=/var/www/example.com/htdocs

 
If you prefer to use a graphical interface, you can find examples here (to adapt) for cPanel or in this video:
 

Sorry, your privacy settings doesn’t allow you to view this embedded video.
To watch it, you must modify your preferences…

 

Conclusion

As you can see, there are several methods to get the WordPress task scheduler to work perfectly.
Whichever method you use, you’ll see that your data is more recent, indexes computation more accurate, and you will notice greater reliability and speed of Weather Station…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Similar Articles

Stay Up to Date

Receive the latest news and updates from Weather Station.