Rate this article :
3.1/5 | 10 opinion
This article was useful to you ?
Yes
No
Vous avez noté 0 étoile(s)
Sommaire
Procédure
A cron job is a mechanism for scheduling background tasks on your web hosting package. It allows commands or scripts to be run automatically at defined intervals.
Cron tasks are defined in a file called a cron file, which specifies which command should be executed and how often.
Cron uses a simple time format to define how often the task should run, such as minutes, hours, days, weeks and months. For example, to run a task every hour, you could set the task to run every 60 minutes.
Cron is a very useful tool for system administrators for automating various tasks, such as backing up data, updating software, sending emails, etc.
1. Connect to your hosting and click on"Cron tasks" in the "Database & PHP" section.
2. Enter the name of the task, the address of the script, the repetition interval and the days and times when the task will run.
1. Connect to your hosting and click on"Cron tasks" in the "Database & PHP" section.
2. You can delete or pause cron jobs if necessary.
Script address : | php /htdocs/my_script.php |
Common parameters: | Once a day |
Execution time: | Choose the execution time from the time drop-down window |
Script address : | php /htdocs/my_script.php |
Common parameters: | Once a week |
Day(s) of execution: | Choose Wednesday in the "day of the week" drop-down window. |
Run time : | Choose "6 p.m" in the "Time" drop-down window. |
The 'Execution time' variable is only taken into account if the task is repeated every 24 hours, otherwise the execution time will be the time the cron was added.
You can log your cron job by adding the following directive to it: &> /htdocs/cron.log
You can replace cron.log with the name of your choice. The command would then be as follows:
php /htdocs/monscript.php &> /htdocs/cron.log
If you have an LWS Starter package or higher, you can modify the cron job for your package via the Web Terminal accessible from your package administration.
To do this, connect to your hosting and click on"Terminal" in the "Software" section.
Access the cron file using the following command:
crontab -e
Once in the cron file, browse the file for the task you want to modify. Each line in the file represents a separate task. Then modify the cron job, making sure that the syntax remains correct. Then save it using the keyboard shortcut [CTRL] +X then"Y". Then press [Enter].
You can then check whether the cron job has been correctly modified by using the following command:
crontab -l
If the URL indicated in the"Script address" field is of the type: http: //mondomaine.com/tache.php?id=200, you will need to call the CURL function which will call your URL.
CURL and PHP are two different technologies that can be used to run cron tasks.
CURL is a command-line tool for transferring data from a URL. It can be used to make HTTP and HTTPS requests and is often used to download data from a website or to make API requests.
PHP is a programming language that can be used to develop web applications and perform tasks on the server. PHP can perform HTTP and HTTPS requests similar to CURL, but it can also execute code and manipulate data in more advanced ways.
When it comes to cron jobs, both can be used to run tasks in the background on a server. However, the difference between the two depends on what you want to achieve. If you just want to make an HTTP request or download data, CURL may be sufficient. If you want to perform more complex tasks, such as analysing data, manipulating databases or generating reports, PHP will probably be more suitable.
To do this, you can introduce a cron job such as the following:
curl /htdocs/tache.php?id=200
CURL can be used to perform a number of cron tasks, including :
You can also use the "-f" option on your CURL cron job. This option allows you to define that the script will end with an error code if the request fails. This can be useful if you want to be informed if the request fails, for example if a website is inaccessible or if data cannot be downloaded. When a cron job is run with the -f
option, if the request fails, the script will exit with an error code, which can be checked by the cron job itself or by another script monitoring the execution of the cron job. This can be used to trigger an additional action if the request fails, such as sending an email notification.
0 0 * * * curl -f https://www.example.com/data.json > /var/www/data.json
In this example, the cron job will run every day at midnight and download the data from https://www.example.com/data.json
using CURL with the -f
option. If the request fails, the script will end with an error code. Otherwise, the data will be saved in the /var/www/data.json
file.
Rate this article :
3.1/5 | 10 opinion
This article was useful to you ?
Yes
No
1mn reading
How do I configure PHP on my hosting?
3mn reading
Customisation of error pages
0mn reading
How to access Apache / Php logs
2mn reading
How do you change the PHP version of your Joomla site to 7?
Bonjour,
Merci de votre retour.
Depuis le LWS Panel, et depuis toutes les formules, vous avez la possibilité d'éditer au maximum 5 tâches CRON.
Je vous remercie pour votre attention et reste à votre disposition pour toute autre question ou complément d'information.
Nous vous invitons à contacter notre service support à travers votre espace client, afin de vous apporter une aide si vous rencontrez des difficultés sur cette manipulation. (https://aide.lws.fr/a/268)
Cordialement, L'équipe LWS