tags:

views:

67

answers:

3

I am writing a component for Joomla and there is a specific task that requires an update to some stats every so often. I would like to setup a cron job to do this. The only problem is that requires the user to go and setup the cron to run the php update stats script.

On installation of the component how can I automatically setup a cron job for the user? Is this possible?

I've seen this implemented in the Akeeba backup pro component for Joomla, so I was hoping that I would be able to do the same thing.

Thanks

+1  A: 

All you need to do is write a line to the crontab file, generally stored in /var/spool/cron/crontabs/username. The cron daemon will see that the file modification time has changed and reload it automatically when it wakes up to do its checks

Michael Mrozek
+1  A: 

In theory you can create a crontab file and call it from PHP

<?php
exec("crontab $path_to_cron_file");

in practice it depends on wether the server (if you're on a shared hosting) allows you to do that.

kemp
Thanks, this is what I was after. I found this also answered here:http://stackoverflow.com/questions/2037176/install-a-cron-job-with-a-php-script
Martin
A: 

Another option (less desirable from a server load perspective but easier for users) would be to create a plugin that is run each time a visitor visits the site. It could check whether the process has been run in a specified time and then run it if it needs to be run.

iJoobi.com has another solution where they have set up a server to run cron tasks, which would then ping the specific URL on the website to kick off the process. (http://www.ijoobi.com/Help/jNews/jNews-Cron-Task.html)

Don Cranford
Thanks Don, your first option wouldn't be feasible for sites with high traffic. Nice link for the cron, really cool!
Martin