WordPress handles scheduled tasks like publishing future posts, checking for plugin updates, and sending email notifications using a built-in file called wp-cron.php. However, this is not a true cron job. It only triggers when someone actually visits your website. If you have high traffic, this file runs constantly and drains your server CPU. If you have low traffic, your scheduled posts might be published late because no one visited the site to trigger the check.

By disabling this default behavior and setting up a real cron job directly inside your Sternhost cPanel, you can significantly reduce your server load and guarantee that your background tasks run precisely on time, independently of your site traffic.

Step 1: Disabling the Default WP-Cron

First, you need to tell WordPress to stop checking for scheduled tasks every single time a page loads. You can do this by editing your configuration file.

  • Log in to your Sternhost cPanel account.

  • Navigate to the Files section and click on File Manager.

  • Open your website's root folder (usually public_html) and right-click to edit the wp-config.php file.

  • Right above the line that says "That's all, stop editing! Happy publishing," add the following code: define('DISABLE_WP_CRON', true);

  • Click Save Changes in the top right corner.

Step 2: Creating a Real Cron Job in cPanel

Now that WordPress is no longer handling the schedule on every page load, you must tell your cPanel server to run the tasks on a fixed, predictable schedule.

  • Go back to your main cPanel dashboard and scroll down to the Advanced section.

  • Click on Cron Jobs.

  • Under Add New Cron Job, select 'Twice Per Hour' from the Common Settings dropdown menu (every 30 minutes is optimal for most sites).

  • In the Command box, paste the following line, replacing '[suspicious link removed]' with your actual website URL: wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

  • Click Add New Cron Job.

Why Server-Level Cron Jobs Are Better

  • Consistent Performance: Your website's loading speed is no longer impacted by heavy background tasks triggering right when a real visitor tries to load a page.

  • Reliable Scheduling: Your automated backups, scheduled posts, and newsletter emails will run exactly when they are supposed to, regardless of whether someone is browsing your site.

  • Lower CPU Usage: It prevents simultaneous executions of the wp-cron script, which is one of the most common causes of resource limit warnings on shared hosting.

Дали Ви помогна овој одговор? 0 Корисниците го најдоа ова како корисно (0 Гласови)