How to Time Things in WordPress – Cron Job Plugin

I was reading a comment online about the difficulty of doing Cron jobs. Cron jobs currently make sure *NIX programs run on time. Execution of programs – a complicated topic for a simple thing like scheduling events.

The problem is Cron – it’s a powerful program, and a lot of times all you want to do is run something approximately every 15 minutes, once a day, etc.

As well, some web hosts prevent cron jobs.

What’s a WordPress blogger to do?

So I sat down and wrote very simple plug-in. What you do is enter in a series of URLs, and a time. It then checks them by loading in the webpage or PHP code (or whatever the URL points to]), and you end up triggering whatever code is on that page.

You can download the WordPress cron plugin (Utopia Cron) here.

Installation is simple: download, unzip the utopia38.php file, upload it and activate. Go to Manage/U-Cron and enter the URL and timing info of the page(s) that you want loaded.

Then, as your blog pages are loaded, the program will visit each URL you entered in turn. Depending on what the page does, it may activate something, or just load.

  • For example the free banner ad program phpAdsNew/OpenAds requires the page maintenance.php to be loaded every hour – you would enter the full URL of the page on your system, specify a start time, and then a frequency of 1h – if the start time is 00:20, then you would check approximately at 00:20, 01:20, 02:20, etc.
  • Another example is WordPress blogging by email – you can set up your email account in the Options/Writing/Post subtab, but you need to load/view the wp-mail.php file to actually check for posts. Use this to check every few minutes, and emails will get posted easily (and you’re also avoid tying up resources by checking TOO often).

Note: after you enter a URL, test the page to make sure it loads properly, and view it to make sure you’re loading the right page. On WordPress blogs, if the page is wrong, you might get a 404 page, which is NOT an error from the plugin’s point of view.

So, give it a try see if it helps with your timed jobbies.

40 thoughts on “How to Time Things in WordPress – Cron Job Plugin

  1. I have installed it, and it works when i trigger it manually, but it doesn´t schedule and work with timers set…. what´s the trick?

    Rune

  2. One possibility is you’re using an old theme – it needs wp_footer() in the footer.php file (or anywhere near the bottom) to run.

  3. Hello again, and thanks for your answer.

    The thing is, I use WP-O-Metic, and have added some rss feeds to the list of campaigns.

    As you probably know, there is a “fetch” link to the campaigns. Running the fetch from here, works smoothly. Copying that link to the ucron, doesn´t help much. If I hit the “view page” link in ucron, the fetching is performed. But the “schedule”, does not seem to work. I have set the settings to “10m”, with the start time at 00:00. I am trying to load the webpage (enduser) several times, but nothing happens.

    I have checked the template, which is the Revolution Blog Template, which do include the footer.

    Any ideas?

  4. I tested it here, and the two work together fine. Some thoughts:

    1) the feed plugin requires a security code included as part of the url – without it, it will fail.

    2) cron is an ‘approximate’ timer – it can vary by as much as four minutes from the expected time.

    3) blog page loads are used to time the cron plugin – if you get few visitors, the timer will be sluggish (eg if you time something every hour, and no one visitors in three hours, only the last hourly call will work).

    4) not every site allows page loading in PHP – if your WP dashboard doesn’t load for instance, then this plugin won’t work, either.

    You can use the test buttons in the cron job to see if everything is working/loading.

  5. The dashboard loads. No problem. Can it be that my ISP does not provide support for cronjob or curl()?

  6. This plugin means you don’t need cronjobs, so that isn’t an issue, and if the dashboard loads, then this plugin should work (it uses similar code). Try the ‘test’ button – this will let you test it without waiting for the timer to count down, and will give you an error message if it fails for any reason. If it succeeds, then the problem must be with the other plugin.

  7. As pointed out earlier, – the testbutton works. I cant understand what this is. Everything seems to be working nicely, besides the pure scheduling of it…

  8. This is what I have one:

    1. Created a campaign in wp-o-metic. Tested it. It fetches and posts are created. I copy the link behind the FETCH link.

    2. I enter u-cron, create a entry, start time 00:10, check every 10m, the url i copied are pasted in the url field. I save it. Test is ok. If I click “view page”, it fetches, and posts are created.

    3. But, nothing happens on a schedule….

  9. Addtional info:

    I have now even added a external URL to the cronjobs in ucron, to a server which I have access to all posts/gets requests on the webserver. NONE are performend from the installation of u-cron (scheduled). If I hit the test/preview buttons, then the request is logged.

    So the problem is not only within WordPress, but the cronjob itself. It does not process.

    Comments?

    Rune

  10. I am sorry to spam you like this, but looking more into it, – ucron DOES hit the external url on a scheduled basis.

    Then the problem is, why doesn´t it hit the internal one? Am I using the correct url? (i guess i am, since it works manually).

    Can the answer be this easy: WordPress Ucron plugin runs on a “anonymous” mode, which probably wont work pretty well in combination with wp-o-metic? Which performs a post to the blog?

    Rune

  11. Since the test button works, you are doing the same code as the timer does, with the exception of the timing itself.

    So the question is, what interferes with the timing?

    1) Not enough visitors. Manually refresh the page every five minutes or so. If that solves it, you’ll need a cron job after all (the code is visitor-driven).

    2) Caching pages. Turn off caching – with caching the theme is not called, it’s displayed – so wp-footer isn’t called, and no processing.

    3) Bad theme. Use the default theme to check – if it works, you’re theme is the problem.

    4) Not using full URL – even if it’s local, it needs to be http://egwebsite.com etc…

    You need to divide and conquer – I’ve created a test script you can use to email yourself results at http://ActiveBlogging.com/info/troubleshooting-utopia-cron/

  12. 2: How can i turn off caching? in a ISP environment? is it a application setting in WP or serversetting for ISP?

  13. The caching would be an addon plugin like wp-cache or supercache – if they are on, turn them off to see if the problem goes away – also, in the other post I mentioned I included an email script to test – give it a try, follow the steps I mentioned, and try to isolate where the problem is occurring.

  14. After upgrading to WP 2.7 there is no longer a Manage tab in the WP Dashboard (It’s replaced by Settings) and U-CRON is not listed under Settings.

    U-CRON still shows up in Plugins and is active and seems to be working but there is no longer any way to configure it.

  15. WP 2.7 changes the menu layout significantly – the U-Cron tab is now in the ‘Posts’ section, at the bottom.

  16. Hey,

    Another (simpler) solution to this problem is the service I created: Cronless.com. You get a free online cron job with your account sign-up and it’s perfect for bloggers. Use it to automate posting. Much easier to use/configure than the WP-Cron plugin.

    Hope that helps!
    -Dave

  17. >>Much easier to use/configure than the WP-Cron plugin

    Using Utopia Cron is pretty simple – activate, and add URLs in the Admin page. I haven’t worked with WP-Cron however, so I can’t compare how easy that is. Also, Utopia Cron allows unlimited URLs entered – your site allows a small number (around 5?) before subscribers have to upgrade to the (paid) premium service.

  18. Hi,

    I installed your plugin to run a wordpress page every hour.

    But my page is published as private and I think that the cron doesn’t execute properly.

    Is there a way to it work as if I was logged in?

    thx

  19. Unfortunately, no – the plugin runs a URL every time, and so you need to include the password in the URL (GET variables instead of POST ones). However, a quick test showed that adding “?password_post=xxx” (with a valid pwd) to the line did not give WP the password – so it only works with the password form, so you can’t do it this way.

    Be sure to use the plugin’s test button to see how the program reads the URL – this may give you a workaround or clues as to what is not running right. Don’t forget, once you log into a password-protected page, the password is reused until you close the browser or ‘forget’ your cookies.

  20. It looks like this plugin can do pretty much what i want, but im not sure which link (or file) should i call?

    im using a rss feed widget (image feed widget) and i want basically to updates the feeds every 3hours.

    Apparently wordpress is doing it once a day, but i need some more often refresh

    Would love some help on that 🙂

    Thanks

  21. Anything you have the plugin call needs to be in the form of a URL (with http:// in front). If you can’t do it (or for example it needs a password or cookie value you can’t pass as part of the URL) then it it won’t work.

  22. David,

    Thanks for your answer and I totally understood that,
    But the question is what URL should i call to have wordpress refreshing the cron ? (or refreshing the front page)
    its not a password protected page neither a cookie value.
    I just want to the feeds (coming from the plugin) refreshing every 3hours.

    Thanks

  23. Unfortunately, it depends on the code you’re using – check its documentation for something like a polling URL or URL to call to process the feeds. And confirm that the plugin can be run more frequently – if a plugin has a URL you can call but refuses to refresh every 3 hours, calling it more often won’t make a difference.

  24. Hey David,

    First of all thx for your nice plugin. it’s very helpful since not each webhoster offers the possibility of setting up cron jobs manually.

    but there is a small bug in your plugin according to the latest wordpress version:

    No Navigation in the backend menu is displayed. So simply remove the line 351:

    add_submenu_page('edit.php','U-Cron','U-Cron',9,'u38_menu','utopia38_menu');

    with this one:

    add_submenu_page('tools.php','U-Cron','U-Cron',9,'u38_menu','utopia38_menu');

    have a nice day!

  25. Thanks for the update – while not exactly a bug (the UCron entry is found under the ‘Posts’ links rather than the ‘Settings’ tab), it’s due to the way WP has changed from version to version. The next version of UCron will fix this – unless WP changes things again…

  26. I’m very new to this “cron” stuff and am trying to understand what URL I would use in the situation where I have scheduled posts for a self-hosted WordPress blog that I want the plugin to find or pull so that the posts are added on schedule.

    You may wonder why I need to use a cron job for this and it is because I have many blogs with scheduled posts so it is overheating my cPanel resources and I thought that this might be a solution to that issue.

    If it cannot work for this situation please let me know and also let me know if you have any other possible solutions.

    Thanks,
    Chris

  27. Chris – think of cron as a browser on an automatic timer. It loads a web page for you every 10 minutes, 1/2 hr, or whatever. WHAT page it loads depends on what you are working with – the developer of the product (or plugin, or whatever) should tell you what to call to update their ‘service’.

    On the other hand, if you are using cron to autopost, do you know that WordPress handles that automatically? Set up each article in your blog with a different date and post that – no cron necessary (actually, WP has that cron job built into it). If your articles are already in WP, you can use my autoposting plugin to space them out and save the editing.

  28. hi dave..
    can i use this plugin to manage / autorun my other plugin ?
    thanks

  29. I have implemented U-Cron plugin but when i clicks the test button them message came “connection failed (10060)”.
    Can anybody tell me the cause of this error and how to rectify.
    Thnx in advance

  30. Do not use the cron job plugin unless you first try it out and verify that it is not causing your website to load slowly. Using page loading to perform tasks that are best handled via the cron job is potentially asking for problems. In fact, the automatic WordPress upgrade plugin will slow the website down to a crawl if no page is loaded for around fifteen minutes. Then the first visitor to hit the site loses. Almost twenty seconds to load.
    .
    If your hosting service doesn’t allow chron jobs then find a new hosting service. That simple.

  31. David,

    I am new to WordPress, so spent ‘a while’ swearing at the screen before I found your post:

    “WP 2.7 changes the menu layout significantly – the U-Cron tab is now in the ‘Posts’ section, at the bottom.”

    Thanks so much for sharing your knowledge & restoring my sanity!

    Warmest,

    Nick

  32. Good plugin but i have a problem.
    I want to make a cron job to a page that read a simplepie function and create 2 post with the RSS.

    The problem is that the page with the cron job create only 1 post, but if i go to the Page it create 2 post, why ?

    Is a problem with the function: foreach ?

  33. Perhaps the web page passes some variables via POST, including the count. If the cron only does one, then just set up two jobs, if possible. Or perhaps it is possible to call the web page with GET variables, like ?i=2 or something, so that you can do two calls.

  34. This may be off topic, yet I feel like I may have the right audience here for my question. I just recently written a plugin. That plugin, upon activation, uses a hook that will use wp_schedule_event() to start a daily job. This functionality seems to work just fine and I see the job via the wp-crontrl plugin.

    Unfortunately, the job never executes, unless I view a page or post.

    Is there a way to write a WP plugin that will “wake up” once a day and trigger a PHP function?

    It looks like the cron framework in WP is not really mean to trigger events based on frequency as the wp_schedule_event() function suggests, yet rather is bound to the fact people viewing pages to trigger jobs.

    Any insight, sample code, ideas would be much appreciated.

  35. Unfortunately, WordPress is only run when viewed, either in Admin or a page view (including things like RSS feed viewing), so hooking to its internal cron still make you dependent on page views. Using an external cron job that loads a page would give you more control.

  36. I have a fantasy baseball website and how your plugin might be able to help me? Basically I want to be able to put team rosters (baseball players) on a page and while the games are played, I want the statistics to update automatically as they happen.

    Example: […]

    If you’re familiar with fantasy sports, it’s basically a live scoring / stat tracking feature I’m looking for.

    Any help would be greatly appreciated.

    -Tony

  37. Hi
    I want to try this plugin but after I installed it I can’t find Manage/U-Cron

  38. Hi. I’ve been looking for a plugin like this one, and I’m happy I found it. I’ve tweaked it a bit to play nice with WordPress 3.2.1 because I was getting some notices about deprecated functions and so. I’ve not tested it whatsoever, I just got ride of all the notices right now and hope my change from class-snoopy to class-http will behave well, but if you want me to send you the modified code I’d be glad to. Anyhow I will be testing it and will let you know if it works.

  39. The problem is that the page with the cron job create only 1 post, but if i go to the Page it create 2 post, why ?