What would cause cron jobs to fail? WordPress site unresponsive after migration

After a server migration, on a custom-configured server, a large WordPress site is becoming unresponsive once moderate traffic is pointed at it.

There seems to be no seemingly apparent reason for this, as server specs are very much sufficient. One clue is cron jobs are not running. Refreshing pages will not trigger them to run, and they report as "running now" or are scheduled for -40+ years ago (aka, to force them to run now)

However, this fixes it, in wp-config: define(‘ALTERNATE_WP_CRON’, true);

But, why? I feel like this is a symptom of what is wrong with the migrated website, as it does not function at all once it receives traffic (20+ second loading, and/or unresponsive). CPU load/etc, is withing "normal-high" range, aka normal. It just, seemingly dies. Disabling/enabling cache and cloudflare doesn’t change anyhting. The original site, same settings, functions great.

What would cause cron jobs to fail and a server to not handle traffic after a migration to a freshly configured server?

Can Cron cause the site to go down or DDos attack?

Yesterday I started running a cronjob [code below] on my server

('*/1 * * * *', 'api.cron.sync_with_elastic',['nginx-access-logs']) 

In the morning I got a message that my website is down. I was unable to even SSH, I switched off the server from dashboard my cloud provider has provided and then restarted it. Below is the metric of the website in the last 24 hrs. enter image description here

Is this a DDoS attack or cron has caused this issue?

How to compute the number of occurrences of a cron schedule over a time span?

For example, given a cron schedule such as: 0 * 1 7 6 and a time span, like the next year, can you directly compute the number of times the schedule will fire? It can be brute forced pretty trivially but I’d like to use this to sort a list so I’d rather not just brute force it. It’s pretty easy to compute the trivial cron patterns:

fn('* * * * *', 1 day) -> 60 * 24 fn('0,30 * * * *', 1 day) -> 2 * 24 

It’s easy up until the calendar gets involved with different length months and then you have to worry about days or the week coinciding with days of the month.

Why cron jobs didn’t be set correctly by Ansible playbook?

I created this playbook to set crontab:

- name: Set PATH to crontab   cron:     name: PATH     env: yes     user: barman     job: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/var/lib/barman/.local/bin:/var/lib/barman/bin:/usr/pgsql-10/bin/  - name: Automatically run backup for App1   cron:     name: "Run Backup for App1"     minute: "0"     hour: "3"     user: barman     job: "barman cron && barman backup app1"  - name: Automatically run backup for App2   cron:     name: "Run Backup for App2"     minute: "0"     hour: "4"     user: barman     job: "barman cron && barman backup app2" 

But I only found this under /etc/cron.d/barman file:

# m h  dom mon dow   user     command   * *    *   *   *   barman   [ -x /usr/bin/barman ] && /usr/bin/barman -q cron 

It seems didn’t set task correctly.

WP Cron jobs loops infinitely

I am writing a script to add a named Cron job that updates a single user, that runs every 5 minutes or so.

My problem is that the job runs for every user over and over again every second or so. Here is the code that I have placed inside my functions.php file.

This is my first foray into the WP Cron functionality with WordPress and would like to know if I set up the jobs correctly.

function so_custom_cron_schedule( $  schedules ) {     $  schedules['every_5_minutes'] = array(         'interval' => 300,         'display'  => __( 'Every 5 minutes' ),     );     return $  schedules; } add_filter( 'cron_schedules', 'so_custom_cron_schedule' );  function update_social_user($  user_id){   $  user = get_userdata($  user_id);   if(!$  user){     return;   }   var_error_log('running for '.$  user_id); }  function assign_cron(){   $  users = get_users([ 'role__in' => [ 'administrator', 'seller'] ]);   $  args = array(false);   foreach($  users as $  user){     $  hook_name = 'update_fb_'.$  user->ID;     add_action($  hook_name,'update_social_user');     if(!wp_next_scheduled($  hook_name,$  args)){       wp_schedule_event(time(),'every_5_minutes',$  hook_name,array($  user->ID));     }else{       var_error_log('Already set');     }   } }  assign_cron(); 

Real cron killed my cron system. Only define( ‘ALTERNATE_WP_CRON’, true ); works

my host recommended me to disable wp cron for a real cron due to excessive executions.

the cron system broken immediately and scheduled tasks were not happening.

deleting real cron and turning on wp cron did not work.

through random luck, i tried define( ‘ALTERNATE_WP_CRON’, true ); and it worked.

having said so, i really want to revert back to the prior situation where normal wp cron works. it also messes up when all my links start to have &doing_wp_cron=

i have spent many hours and am desperate! appreciate your kind advice.

I’m using PHP 7.1 but Hostgator says they are on 5.4, and Cron throws an error

Trying to make sense of this. Doing a quick phpinfo() I get:

PHP Version 7.1.14 System  Linux gatorxxxxx.hostgator.com n.nn.nnn-nnn.nnn.nnn.x86_64 #1 SMP Tue May 21 13:24:40 CDT 2019 x86_64 

But when I try to install a cron that hits a URL every 30 days for the Auto-Install-free-SSL plugin that I’ve been using for years on a different host, cron reports:

Your server is running PHP version 5.4.45 but WordPress 5.3.2 requires at least 5.6.20.

Got Hostgator on the phone and they reported that all shared hosts are still on 5.4.x which fits the error message, but if phpinfo() is showing I’m on 7.1… what the heck is actually going on here? How can I get cron to also use 7.1 so the command will execute?

Cron job not creating snapshots

I have a cron job set up in my crontab which is set to fire a snapshot every first minute of an hour. When I see the cron logs I can see that it triggered the task but I do not see the snapshots in Kibana client. I curl’ed the ElasticSearch instance directly and do not see the snapshots there either. When I try to run the cron script manually from one of the nodes it works fine and creates a snapshot but surprisingly the crontab job does not do so.

Here is my cron job setting

< 1 * * * * root curl -v -k -s -X PUT https://:@localhost:9201/_snapshot/s3_backup_repository/%3Csnapshot-%7Bnow%2Fh%7Byyyy.mm.dd-hh%7D%7D%3E?wait_for_completion=true >> /opt/elasticsearch/system/system.log 2>&1 />

This cron job is set on all the three EC2 instances in our ES cluster.

Here is the row in cron log in /var/log/ which shows the script was triggered per the cron schedule. (I see this in all the 3 EC2 instances in ES Cluster all with the same timestamp).

< Sep 28 18:01:01 ip-10-7-22-136 CROND[17730]: (root) CMD (curl -v -k -s -X PUT https://redacteduser:redactedpassword@localhost:9201/_snapshot/s3_backup_repository/) />

The system.log file in all the 3 instances on path /opt/elasticsearch/system do not have any trace of the snapshot triggered by the cron tasks.

Any idea why this could be happening? Is it because all the 3 instances in the cluster try to trigger the snapshot all the same time?

Thanks, Rahul

Cron job not working (CURL)

I have a server using Linux 19.04

First I did: nano /etc/crontab

The below things were already in the file

SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  # m h dom mon dow user  command 13 *    * * *   root    cd / && run-parts --report /etc/cron.hourly 18 00   * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 33 00   * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 43 00   1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) # 

I added this one at the end before # line

*/1 * * * * curl -s "https://www.example.com/abc" > /dev/null