Creating a cron job / task
You can create so-called cron jobs: programs that run at preset times. It is not allowed to create cron jobs that run more often than once every 10 minutes. Heavy cron jobs (that put an extreme load on the processor) are not allowed either. After all, there are other websites running on the same server. You do not want to be bothered by others, and others do not want to be bothered by you. WebOké may terminate cron jobs if necessary. The rule is that a cron job may not run for longer than 10 seconds. If you want cron jobs to run more often, this is allowed from the POWER WEBHOST packages upwards.
If you create several cron jobs, this applies to the total, so please start no more than 1 cron job per 10 minutes. Spread your cron jobs well, as this benefits server performance.
Preferably include this statement in your cron job: set_time_limit(10). This makes your cron job stop if it takes longer than 10 seconds. You enter a cron job in the control panel.
What does a cron job look like?
A cron job that starts a PHP program, for example, looks like this:
/usr/local/bin/php -q /home/<usrdir>/domains/<uwdomein.xx>/public_html/<taak.php>
Replace <usrdir> with your DirectAdmin username, <uwdomein.xx> with your domain name and <taak.php> with your PHP script.
Email sent after every cron job
By default, an email is sent to your default email account. This email shows any errors from the cron job, as well as any output. You can view that mailbox at webmail.weboke.nl by entering your account name as the username, your password and the server name. If you no longer want to receive an email every time, add this after the cron job: /dev/null 2>&1
Paths are slightly different from FTP
You need to put the full path to PHP in front, as well as the full path on the server to the PHP program. That is different from FTP: now /home/usrdir comes first. Replace usrdir with your own username (the one for the control panel).
Important!! A cron job has no domain name
Also note that a PHP program run from a cron job does not know which website it is running under. $_SERVER['SERVER_NAME'] is empty, and an include will also fail because there is no base path!!
Example code to include in your cron program to prevent this:
- $pad = "/home/<usrname>/domains/<uwdomein.xx>/public_html"; (make sure to replace <usrdir> and <uwdomein.xx>!!!)
- $_SERVER['SERVER_NAME'] = 'uwdomein.xx';
- $_SERVER['DOCUMENT_ROOT'] = $pad;
- set_include_path($pad . PATH_SEPARATOR . ini_get("include_path"));
