Opened 8 years ago
Closed 3 years ago
#33863 closed enhancement (wontfix)
uksort takes a lot of time with large number of cron events
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 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:
- Disable collecting cron events where DISABLE_WP_CRON is set to true
- Limit the size of the array
- Try to avoid sorting (memory problems still will occur)
Please contact me if any information is needed.
Change History (7)
#2
@
8 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
@
8 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
@
8 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.
#7
@
4 years ago
Creating a custom storage system for site's with a large number of scheduled tasks is now possible with the changes introduced in WordPress 5.1, please refer to the dev note on the Make WordPress Core P2.
DISABLE_WP_CRON
only disables WordPress calling the cron, the constant is designed for when someone is using a external tool (such ascurl
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..