Cron not working properly

This topic contains 11 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years, 5 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #24033
    iOio
    iOio
    Participant

    Hello,

    problem is cron indexing. It works like 3-4 times and then it stop working.

    I have enabled this:
    Use wp_cron() to extend the index table automatically?
    Will register a cron job with wp_cron() and run it periodically.

    Is there any way how to add cron to server to have better control? Or it is not possible and only plugin can handle it by itself.

    Can there be some specific thing to need to be enabled on server? I have it on VPS.

    Thanks.
    Regards,
    Jozef

    #24036
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Jozef,

    The cron jobs are managed by WordPress, the plugin only registers the cronjob itself, and the period when to run. These are not the classical server triggered cron jobs though. It only works when a page is opened, so that PHP is triggered, and WordPress is initialized. It checks if there are any cron jobs due, then executes them. Therefore it is not possible to have this server controlled.

    Maybe as a bypass solution you could set up a server cron job, that simply opens the site front-page, thus triggering WordPress to load. Setting it to maybe 5 minutes or so would trigger every remaining cron job.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24045
    iOio
    iOio
    Participant

    Hello,

    so if I understand it correctly, when there is traffic or the website is viewed, any page, and there is cron scheduled, it will execute itself, right?

    I setup twice daily yesterday and it was executed in midnight, I will check if it stop working, now it seems it works but afaik it will stop after 3-4 times it will be executed. I will check that and let you know if there is still problem.

    Attachments:
    You must be logged in to view attached files.
    #24047
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Yes, that should trigger the wp_cron actions in wordpress, however I don’t exactly know if there are multiple cron events, how it is distributed, if distributed in any way.
    I have checked the cron related source code, but I don’t see any issues there, the only section where the cron jobs are deleted, when the new settings are saved on the index table options – but right after that, the new cron jobs are immediately registered again.

    The execution timer can be inaccurate, I would rather check if there are any posts left to be indexed. If the counter stays on 0, or gradually lowers (if many posts are added), then it should be fine.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24273
    iOio
    iOio
    Participant

    Hello,

    it just doesn’t work as it should, there are hits on website but:

    Last execution info
    Last exeuction time: 00:02:35, September 25. 2019
    Current system time: 15:18:43, October 9. 2019
    Posts indexed: 0
    Keywords found: 0

    Items Indexed: 13832 | Items not indexed: 76

    #24278
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Looks like the cron is not triggered then as it should. I have tested the cron event on a server, but everything seems to be okay in terms of it’s registration for execution. I suspect that either something is clearing the cron-jobs, or preventing their execution. Once the cron is registered, it is up to wordpress for execution.
    May I ask what timeframe is the cron set to be executed? Can you try the lower values, like 5 minutes or so? If there is something regularly clearing the cron jobs, that might prevent that.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24279
    iOio
    iOio
    Participant

    I have it now twice a day, it seems it runs only once a day after midnight, that is strange and it works only for 3-4 days then it stop working completely.

    Can you try the lower values, like 5 minutes or so? If there is something regularly clearing the cron jobs, that might prevent that.
    Sure I can try it but what happens if first cron indexing will last for 20 minutes or so? And another cron is in 5 minutes?

    #24281
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    It cannot last that long. PHP script execution is usually hard-coded within the server to stop in 30 seconds or even less. The cron indexing only does one single iteration of 25 items at once ( or as set on the back-end here: https://i.imgur.com/hLRYKVm.png ). That usually lasts like 1-5 seconds tops, depending on post lenght and server performance. It can’t do any harm, as if there are no items to index, it will not do anything, just check.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24286
    iOio
    iOio
    Participant

    Ok I will try 15 minutes and will see but cron only start when there are items to index? Or it doesn’t matter?
    Yesterday I did manual continue indexing and I have Last exeuction time: 00:02:35, October 10. 2019, I did it in 6pm or so, so the cron was working later somehow.
    Now I have 15 minutes but last execution is from midnight still.

    #24287
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Yes, it first checks if there are items to index, and if there is none, then nothing will happen. This check is also part of the cron job basically.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #24431
    iOio
    iOio
    Participant
    You cannot access this content.
    #24447
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I honestly don’t know, programatically everything seems to be okay.

    Well, I found a custom code from a different ticket, where the user was requesting a manual CRON job, that he wanted to execute on his server, via triggering a URL.

    I recommended this custom code to the functions.php file in his theme directory:

    add_action( 'init', 'asp_cron_trigger' );
    function asp_cron_trigger() {
      if( isset( $_GET['asp_cron_trigger'] ) ) {
        $o = new WD_ASP_IndexTable_Action();
        $o->extend();
        $asp_cron_data = get_option('asp_it_cron');
        if ( isset($asp_cron_data['result']['postsIndexedNow']) ) {
          print 'Ajax Search Pro Index Table Extended<br />';
          print 'Indexed: '.$asp_cron_data['result']['postsIndexedNow'];
          print ' | Keywords found: ' . $asp_cron_data['result']['keywordsFound'];
        }
        die();
      }
    }

    Then basically visiting this link:
    yoursite.com/?asp_cron_trigger
    ..would trigger an index table extend event. He then put this to his cron table on the server side via SSH and curl I think. I’m not sure if this still works, but since something is cleaning up the wordpress cron job, this might be a possible alternative.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.