WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 16 months ago

#33863 new enhancement

uksort takes a lot of time with large number of cron events

Reported by: geza.miklo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.3
Component: Cron API Keywords:
Focuses: Cc:

Description

wp-includes/cron.php: 49, 91

If crons are disabled in wp config:

/** Disable cron jobs */
define('DISABLE_WP_CRON', true);

Then the events just get collected and collected. We've imported more than 500k articles, and during that the cron array stored in the options table bacame huge. I mean really, really huge.

On every request it got loaded, parsed and sorted. https://secure.phabricator.com/book/phabflavor/article/php_pitfalls/#usort-uksort-and-uasort

Quick fix with filter:

add_filter('schedule_event', function() { return false;});
add_filter('pre_option_cron', function() { return array(); });

We are using wp-cli to run jobs. For the most needed we've written our own command (eg. activating future posts).

I see three options (two real solution exactly) to fix this error:

  1. Disable collecting cron events where DISABLE_WP_CRON is set to true
  2. Limit the size of the array
  3. Try to avoid sorting (memory problems still will occur)

Please contact me if any information is needed.

Change History (5)

#1 @dd32
2 years ago

DISABLE_WP_CRON only disables WordPress calling the cron, the constant is designed for when someone is using a external tool (such as curl via a system cronjob) to execute the actual cron script.

Due to the reliance upon cron, I don't think we want to make it easy to completely disable it though like you're doing..

#2 @geza.miklo
2 years ago

I understand and agree with your opinion. But I don't feel, that is makes sense to let the cron option grow without a limit.

#3 @dd32
2 years ago

FWIW though, you might also be being bitten by #33423, as the cron array isn't processed on every page load normally.

#4 @geza.miklo
2 years ago

Yeah it won't be, because I dont want it to be processed. You can't let it do that, if over a million pages are requested per day.

#5 @swissspidy
16 months ago

  • Component changed from General to Cron API
Note: See TracTickets for help on using tickets.