Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[documentation] - Configuring cron jobs #2747
Configuring cron jobs using the cron command
Cron is a daemon that executes commands at specified intervals. These commands are called "cron jobs." Cron is available on Unix, Linux and Mac servers. Windows servers use a Scheduled Task to execute commands.
For a modest personal site, you might set up this cron job to run once a day. For a more active site, you might want to run that job more often - perhaps every few hours or every hour.
Each e107 version has a different URL, you must request for cron to trigger. For e107, the URL contains a token, which is a "secret key" to prevent external abuse.
The cron command
In the following example, the crontab command shown below will activate the cron tasks automatically on the hour:
In the above sample, the
The rest of the line
How to set up a cron job
Cron jobs are scheduled by setting up a "crontab." A crontab is a text file that contains the commands to be run. This file can be created and edited either through the command line interface, or, if you manage your website through a web-based control panel such as cPanel, IspConfig, Plesk, or Virtualmin and Webmin, you will use the web interface.
To edit a crontab through the command line, type:
Add ONE of the following lines:
This would have a lynx, wget, or curl visit your cron page 45 minutes after every hour.
Three options are provided in case either wget, lynx or curl are not installed on the server. Any will do the job well.
Learn more about the crontab file syntax here to set up the cron job to run more or less often.
There are many ways to configure a cron job. If you have full access to crontab features, you should be able to simply paste in one of the above example commands – be sure to replace "example.com" with your own web domain or docroot.
If you're on shared hosting, you should be able to find cron job configuration somewhere in your hosting control panel. Some hosts even have cron "wizards" that walk you through the cron configuration, making it much easier if cron is new to you. On a Windows system you can accomplish the same thing with scheduled tasks to launch Internet Explorer pointed to the URL.
Some hosting companies do not permit local loopback, so using wget, curl or lynx will not work. If this is the case, and they run PHP as a CGI (check with your hosting company to see if this is the case), the following will run the cron locally:
Some hosting companies don’t allow access to cron
If your hosting company restricts access to cron, you have many options.
Troubleshooting cron jobs
If you receive a permission denied error after starting crontab -e, you may need to use sudo:
You may need to adjust the path to wget, lynx or curl in your crontab. For example, the cron example listed above contains the line:
However, Lynx may be in a different location on your server, or not installed at all. To find out where Lynx is installed, enter:
If it is not located at
When using SSL, add one additional argument when calling wget:
If your server is behind a proxy, you might need to add
Configuring cron jobs with Windows
To setup a Windows machine to run cron.php at a specific time follow the specific instructions below. This can be useful if you are not familiar with Linux/Unix, or if your web host does not offer the ability to run cron jobs; you can run them remotely from your own computer.
Note: These instructions were written for Windows XP but should be similar in other versions of Windows.
Creating a Scheduled Task
Configuring the task
Another way to perform the above commands is by using the schtasks (or at in Windows 2000) command from the command line. To duplicate the example above, which runs Firefox hourly to execute http://www.example.com/cron.php?token=TOKEN, open a command prompt (Start > Programs > Accessories > Command Prompt) and enter:
Enter your password if prompted.
Using wget for Windows to run cron
If for whatever reason you'd rather not deal with a browser window popping up on the machine, you can use wget, the Windows port of which works more or less the same as it does in UNIX. curl and lynx also has windows ports, but wget is probably the easiest to set up and use.
Follow the steps for Creating A Scheduled Task above, except select wget.exe as the program to run (you may need to click the Browse button to locate it if you installed from a .zip file, for example). When you get to the Advanced Properties dialog, paste in the following after the program path:
Adjust the rest of the options as described above and test it.
Using curl with cmd.exe in Windows 7 (or Vista) with Task Scheduler
If you have already installed mysysgit, curl is already present and in the path.
Under Windows 7 (or Vista), using schtasks and curl
Assuming you have already installed mysysgit as described above...
Run cmd.exe as Administrator, then enter the command:
Where /tn is the task name desired (here it's DevCron).
The above command yields a job that will run every hour, indefinitely.
@lonalore ..would be a good one yes;