Cron jobs
- Cron Jobs
Cron jobs are scheduled tasks that run automatically in the background on your MediaWiki server. They are critical for maintaining the health and functionality of your wiki, performing tasks like updating search indexes, purging caches, and running maintenance scripts. This article will guide you through understanding, configuring, and troubleshooting cron jobs specifically within a MediaWiki 1.40 environment.
== What are Cron Jobs?
At a fundamental level, a cron job is a command or script that is executed periodically at specified intervals. The `cron` daemon (a background process) on Unix-like operating systems (Linux, macOS, etc.) reads instructions from configuration files called "crontabs" and executes the corresponding commands at the designated times. For MediaWiki, these jobs are essential for automated tasks.
== Why are Cron Jobs Important for MediaWiki?
MediaWiki relies heavily on cron jobs for several key functions:
- Updating the search index: The [Special:Search|search functionality] depends on a regularly updated index. The `updateSearchIndex.php` script, run by a cron job, keeps this index current.
- Cache maintenance: MediaWiki's [Cache|caching system] requires periodic purging and refreshing to ensure users see the latest content.
- Job queue processing: Many asynchronous tasks, such as sending email notifications or processing image transformations, are handled through a [Job queue|job queue]. Cron jobs process items in this queue.
- Database maintenance: Regular database maintenance, like optimizing tables and removing old revisions, is crucial for performance and data integrity.
- Running maintenance scripts: Various administrative tasks, such as checking for broken redirects or updating statistics, can be automated.
== Configuring Cron Jobs for MediaWiki
The primary method for configuring cron jobs is by editing the crontab file. You'll typically do this using the `crontab -e` command in a terminal. *Always* use this command to edit your crontab; directly editing the files is discouraged.
Here's a basic example of a crontab entry:
`* * * * * /usr/bin/php /path/to/mediawiki/maintenance/runJobs.php`
Let's break down this entry:
- `* * * * *`: This is the cron schedule. Each asterisk represents a time field (minute, hour, day of month, month, day of week). An asterisk means "every". So, this schedule means "every minute of every hour of every day of every month of every day of the week." *Be cautious with such frequent schedules!*
- `/usr/bin/php`: This is the path to the PHP interpreter on your system. Confirm this path is correct. Use `which php` in the terminal to find the correct path.
- `/path/to/mediawiki/maintenance/runJobs.php`: This is the path to the MediaWiki maintenance script that you want to run. Replace `/path/to/mediawiki` with the actual path to your MediaWiki installation.
Common MediaWiki Cron Jobs
The following table lists common MediaWiki cron jobs and their recommended schedules. *Adjust these based on your wiki's size, traffic, and server resources.*
Script | Description | Recommended Schedule |
---|---|---|
`runJobs.php` | Processes the job queue. Critical for asynchronous tasks. | Every 5-15 minutes (e.g., `*/5 * * * *`) |
`updateSearchIndex.php` | Updates the search index. | Every hour (e.g., `0 * * * *`) or more frequently for large wikis |
`purgeCache.php` | Purges the MediaWiki cache. | Every hour (e.g., `0 * * * *`) |
`maintenance/batchDeletion.php` | Deletes pages marked for deletion. Requires proper configuration of deletion policies. | Daily (e.g., `0 0 * * *`) |
`maintenance/archive.php` | Archives old revisions of pages. | Daily or Weekly (e.g., `0 0 * * 0` for weekly on Sunday) |
Finding the Correct Paths
It’s crucial to use the correct paths to the PHP interpreter and your MediaWiki installation in the crontab. Incorrect paths are the most common cause of cron job failures.
Here’s how to find those paths:
- **PHP Interpreter:** Run the command `which php` in your terminal. This will output the full path to the PHP executable.
- **MediaWiki Installation:** Navigate to your MediaWiki directory in the terminal. The full path to this directory is what you'll need.
Example Crontab File
This table provides an example of a complete crontab file for a typical MediaWiki installation.
Time | Command |
---|---|
`*/10 * * * *` | `/usr/bin/php /var/www/mediawiki/maintenance/runJobs.php` |
`0 * * * *` | `/usr/bin/php /var/www/mediawiki/maintenance/updateSearchIndex.php` |
`0 0 * * *` | `/usr/bin/php /var/www/mediawiki/maintenance/purgeCache.php` |
`0 2 * * *` | `/usr/bin/php /var/www/mediawiki/maintenance/batchDeletion.php` |
- Remember to replace `/usr/bin/php` and `/var/www/mediawiki` with your actual paths.*
== Troubleshooting Cron Jobs
If your cron jobs aren't running as expected, here are some troubleshooting steps:
1. **Check the Cron Logs:** The system logs (usually `/var/log/syslog` or `/var/log/cron`) will often contain information about cron job execution, including errors. 2. **Verify Paths:** Double-check the paths to the PHP interpreter and your MediaWiki installation in the crontab. 3. **Permissions:** Ensure that the user running the cron job has the necessary permissions to execute the PHP interpreter and access the MediaWiki files. 4. **Output Redirection:** Redirect the output of your cron jobs to a file to capture any errors or messages. For example:
`0 * * * * /usr/bin/php /path/to/mediawiki/maintenance/updateSearchIndex.php > /path/to/mediawiki/cron.log 2>&1`
5. **Test Manually:** Try running the maintenance script manually from the command line to see if it works. This will help you isolate the problem. 6. **Environment Variables:** Cron jobs have a limited environment. If your scripts rely on specific environment variables, you may need to set them within the crontab file.
== Further Resources
- [MediaWiki documentation on cron jobs](https://www.mediawiki.org/wiki/Manual:Cron_jobs)
- [Cron documentation](https://en.wikipedia.org/wiki/Cron)
- [PHP documentation](https://www.php.net/)
- [Special:Version](https://www.mediawiki.org/wiki/Special:Version) - Check your MediaWiki version.
Special:MyPage
Help:Contents
MediaWiki
Special:Search
Extension:Semantic MediaWiki
Manual:Configuration
Manual:Maintenance
Manual:FAQ
Help:Formatting
Special:Random
Manual:Administrators
Special:ListUsers
Help:Links
Manual:Talk_pages
Manual:User_rights
Manual:API
Special:Statistics
Manual:Database
Intel-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Core i7-6700K/7700 Server | 64 GB DDR4, NVMe SSD 2 x 512 GB | CPU Benchmark: 8046 |
Core i7-8700 Server | 64 GB DDR4, NVMe SSD 2x1 TB | CPU Benchmark: 13124 |
Core i9-9900K Server | 128 GB DDR4, NVMe SSD 2 x 1 TB | CPU Benchmark: 49969 |
Core i9-13900 Server (64GB) | 64 GB RAM, 2x2 TB NVMe SSD | |
Core i9-13900 Server (128GB) | 128 GB RAM, 2x2 TB NVMe SSD | |
Core i5-13500 Server (64GB) | 64 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Server (128GB) | 128 GB RAM, 2x500 GB NVMe SSD | |
Core i5-13500 Workstation | 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000 |
AMD-Based Server Configurations
Configuration | Specifications | Benchmark |
---|---|---|
Ryzen 5 3600 Server | 64 GB RAM, 2x480 GB NVMe | CPU Benchmark: 17849 |
Ryzen 7 7700 Server | 64 GB DDR5 RAM, 2x1 TB NVMe | CPU Benchmark: 35224 |
Ryzen 9 5950X Server | 128 GB RAM, 2x4 TB NVMe | CPU Benchmark: 46045 |
Ryzen 9 7950X Server | 128 GB DDR5 ECC, 2x2 TB NVMe | CPU Benchmark: 63561 |
EPYC 7502P Server (128GB/1TB) | 128 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/2TB) | 128 GB RAM, 2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (128GB/4TB) | 128 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/1TB) | 256 GB RAM, 1 TB NVMe | CPU Benchmark: 48021 |
EPYC 7502P Server (256GB/4TB) | 256 GB RAM, 2x2 TB NVMe | CPU Benchmark: 48021 |
EPYC 9454P Server | 256 GB RAM, 2x2 TB NVMe |
Order Your Dedicated Server
Configure and order your ideal server configuration
Need Assistance?
- Telegram: @powervps Servers at a discounted price
⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️