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.
(Update: I’ve discussed troubleshooting in more detail in this post).
| ActiveBlogging.com - for information on making your blog successful! Get information like this - and more - inside! Details here or Join Today! |



July 12th, 2008 at 5:05 am
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
July 12th, 2008 at 9:09 pm
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.
July 13th, 2008 at 11:39 am
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?
July 14th, 2008 at 2:37 am
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.
July 14th, 2008 at 5:50 am
The dashboard loads. No problem. Can it be that my ISP does not provide support for cronjob or curl()?
July 16th, 2008 at 12:36 am
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.
July 16th, 2008 at 3:58 pm
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…
July 16th, 2008 at 4:03 pm
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….
July 16th, 2008 at 5:38 pm
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
July 16th, 2008 at 5:51 pm
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
July 17th, 2008 at 2:26 am
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/
July 17th, 2008 at 2:41 pm
2: How can i turn off caching? in a ISP environment? is it a application setting in WP or serversetting for ISP?
July 17th, 2008 at 10:54 pm
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.