Saturday, September 3, 2022
HomeWordPress Developmentplugin growth - Working one-off cron jobs when WP_DISABLE_CRON is true: can...

plugin growth – Working one-off cron jobs when WP_DISABLE_CRON is true: can I hit /wp-cron.php?


I’ve a plugin that should do a “database replace” form of operation, going by means of all customers and performing a selected database operation on each. It is designed for websites with giant numbers — tens of 1000’s — of customers. I’ve labored out a very good environment friendly method to do the operation in chunks of 1000 customers. And I’ve labored out a method for every chunk (besides the final one) to schedule the following chunk for a few seconds later with wp_schedule_single_event(). So the “database replace” runs for some time as a well mannered background job.

All good.

Now I am attempting to make this work on websites that use system cron and have WP_DISABLE_CRON set to true. My query is that this: Is there something drastically incorrect with doing this from an unload motion? This code does what a system cronjob does to the location: it hits https://instance.com/wp-cron.php. However it does so extra typically whereas my background job is in progress.

if ( ! wp_doing_cron() ) {
  $url = get_site_url( null, 'wp-cron.php' );
  $req = new WP_Http();
  $req->get( $url );
}

I attempt to respect the disabled inside cron: the location proprietor disabled it for good causes. I’m taking care not to do that until I do know there is a chunk to course of and I do know it has been at the least couple of seconds for the reason that final time I did it.

This appears to be like like it really works. However are there configurations the place it would trigger huge hassle?

(Be aware: wp-cron.php itself does fastcgi_finish_request() promptly when it’s invoked, so my code will not cling for lengthy ready for wp-cron.php to complete.)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments