• Resolved nlpro

    (@nlpro)


    Hi,

    I was wondering whether the WP Crontrol plugin can be used to delete cron events that only have a timestamp.

    It seems the cron option sometimes holds one (or more) timestamp entries with no array() value assigned. Basically invalid entries. Not clear where these come from but there is clear evidence these can exist. Oh if the timestamp is close in the future does it make sense to simply wait for the WP Cron API to clean these entries at execution ?

    Anyway sometimes you don’t want to wait till execution time. Just wondered whether the WP Crontrol plugin allows me to manually get rid of these “events”.

    Oh almost forgot. What is the correct terminology for such events ? Orphans seems to be something else. Perhaps ghost events?

    Really interested to hear from you (or anyone else).

    Thank you in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    I’ve not seen these personally. Does this mean that in the database you have an entry with a timestamp for the key but the value is an empty array? Or a null value?

    I think in this case, if you try to delete one of these events with WP Crontrol it will probably fail to delete it.

    How do these appear in the Tools -> Cron Events screen? Do they appear broken?

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    If you’re happy to send me a copy of the contents of your cron option from the wp_options table I’ll be happy to take a look at this. If there’s potentially private information in there then you can email it to me: https://johnblackbourn.com/about/

    Thread Starter nlpro

    (@nlpro)

    Does this mean that in the database you have an entry with a timestamp for the key but the value is an empty array? Or a null value?

    I don’t know exactly because me opening this topic is related to this topic (Not mine by the way. I’m just trying to be helpful and learn some things along the way).

    I’ve been fiddling with the failing command in php:

    const HOOK = 'itsec_cron';
    
    $crons = _get_cron_array();
    
    foreach ( $crons as $timestamp => $args ) {
            unset( $crons[ $timestamp ][ self::HOOK ] ); //this one fails
            ...
    }

    … to reproduce the PHP Fatal error:

    Fatal error: Uncaught Error: Cannot unset string offsets

    … and the only way I succeeded was with a timestamp ($timestamp) with NO array assigned. An empty array or an array without any itsec_cron key works fine. So my conclusion (though I might be wrong) is that the timestamp does not have an array() value assigned.

    I’ve requested the topic owner to provide you with a screenshot of the Tools -> Cron Events screen.

    Thank you very much for your assistance. Really appreciate it.

    Thread Starter nlpro

    (@nlpro)

    Ok, testing revealed the WP Crontrol plugin does not list any invalid cron events. The plugin code assumes there is an array assigned to every timestamp. While testing your plugin I did get these 2 warnings:

    Warning: Invalid argument supplied for foreach() in /var/www/vhosts/example.com/wp-content/plugins/wp-crontrol/src/event.php on line 202

    Warning: Invalid argument supplied for foreach() in /var/www/vhosts/example.com/wp-content/plugins/wp-crontrol/src/event.php on line 158

    Since they are just warnings it doesn’t break things and code execution continues. It does mean invalid entries are simply skipped.

    Anyway thank you for your input. Marking this topic as resolved.

    • This reply was modified 4 years, 8 months ago by nlpro.
    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the update. I think this sort of broken list of cron events is a bit beyond what you can expect any cron management plugin to handle. There are quite a few ways in which that cron array could be malformed.

    I suspect if you try the wp cron event list command in WP-CLI you’ll see similar warnings and behaviour.

    I hope you can get the issue fixed!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Invalid (empty) cron events’ is closed to new replies.