CRON Events Setup
CRON events are used in the Chauffeur Booking System plugin to automate tasks related to booking management at specific intervals. This includes actions such as sending reminders to customers and drivers before or after the service, as well as managing booking acceptance by drivers. In this article, we will guide you through how to add a CRON event in cPanel, configure it, and troubleshoot it.
Good to Know
For each option in the plugin that uses CRON commands, there is a CRON command provided – simply copy it and use it in your CRON configuration in cPanel.
How to Add a CRON Command in cPanel
- Log in to cPanel on your server.
- Navigate to the ‘Advanced’ section and click on ‘Cron Jobs’.
- Choose the frequency with which you want the task to run (e.g., once per minute, twice per hour, daily, etc.).
- In the ‘Command’ field, enter the command you want to execute. For example, it could be wget, which will trigger various actions related to your plugin.
- Click ‘Add New Cron Job’.
Basic CRON Command in Chauffeur Booking System Plugin
For the Chauffeur Booking System plugin, you can use the wget command to trigger a CRON event based on various actions in the system. A basic command looks like this:
wget 'https://yourdomain.com?chbs_cron_event=1&chbs_run_code=B94965E464EB6637038B189F1735CCB0'
In the command above:
- yourdomain.com is the domain where your plugin is installed. You can replace it with your own domain.
- chbs_cron_event is a parameter that defines the CRON event (e.g., 1 for the first event).
- chbs_run_code is a unique code that identifies the specific task to be performed.
Here is an example with three CRON events:
wget 'https://yourdomain.com?chbs_cron_event=1&chbs_run_code=B94965E464EB6637038B189F1735CCB0' wget 'https://yourdomain.com?chbs_cron_event=2&chbs_run_code=B94965E464EB6637038B189F1735CCB0' wget 'https://yourdomain.com?chbs_cron_event=3&chbs_run_code=B94965E464EB6637038B189F1735CCB0'
How to Set the CRON Event Execution Time
Once you’ve added the command, you can set how often the event will execute by clicking ‘Edit’ next to it.
- Every minute:
* * * * *
- Daily at 3:00 AM:
0 3 * * *
- Every hour:
0 * * * *
After setting the execution time, save your changes.
How to Modify the Command to Avoid Saving Output on the Server
If you want the CRON command to not save any data on the server (e.g., to avoid saving files), you can modify the command as follows:
wget -q -O /dev/null 'https://www.yourdomain.com?chbs_cron_event=1&chbs_run_code=12323FD3D1CC7B416596F8E9FCF2DE23' >/dev/null 2>&1
In the command:
-q
stands for ‘quiet mode’, which suppresses output messages.-O /dev/null
ensures that the downloaded file is discarded and not saved.>/dev/null 2>&1
directs both standard output and errors to /dev/null, ensuring no logs are stored.
This kind of command is useful when you don’t want to store any data on the server.
Good to Know
If the wget command doesn’t work as expected, or if you encounter any issues, try replacing wget with the full path to the command, which is typically /usr/bin/wget. This ensures that the correct executable is used regardless of your server’s path configuration.
Example command:
/usr/bin/wget -q -O /dev/null 'https://www.yourdomain.com?chbs_cron_event=1&chbs_run_code=12323FD3D1CC7B416596F8E9FCF2DE23' >/dev/null 2>&1
How to Check If ‘wget’ Exists on the Server
Sometimes, you may want to ensure that wget is installed on your server. To do this, you can check as follows:
- Log in to cPanel.
- Go to ‘Cron Jobs’.
- Add a new CRON job with the following command:
which wget > ~/public_html/wget_path.txt
- Set the execution time to the closest option (e.g., every minute).
- After execution, check the contents of the wget_path.txt file by accessing it in the browser:
https://yourdomain.com/wget_path.txt
If the file contains something like /usr/bin/wget, it means wget is available at that location and can be used in CRON commands.
How to Debug the CRON Command and Check if It Runs Correctly
If you want to check whether your CRON command is executing correctly, you can debug it:
- Add a new CRON job with the following command to see what happens during execution:
/usr/bin/wget -q -O /dev/null 'https://www.yourdomain.com?chbs_cron_event=1&chbs_run_code=12323FD3D1CC7B416596F8E9FCF2DE23' >> ~/public_html/cron_wget_log.txt 2>&1
- Set the execution time to the closest option (e.g., every minute).
- After execution, open the log file in your browser:
https://yourdomain.com/cron_wget_log.txt
If everything works correctly, you should see an HTTP server response (e.g., 200 OK).
Conclusion
Configuring and debugging CRON events in cPanel is relatively simple and allows you to automate various tasks in your booking system. By following these instructions, you can add a CRON command, customize it to your needs, and check if it’s working correctly. If you encounter any issues, remember to debug, check if wget is available, and log errors for further analysis.
Summary
Document version: 1.0
Last updated: February 25, 2025
Plugin version: 6.8+