WordPress.org

Forums

Cron job only fires if pages are visited - why? (6 posts)

  1. forensicdev
    Member
    Posted 4 years ago #

    I developed a plugin that upon activation (register_activation_hook()) creates a cron job. This cron job is suppose to trigger once a day. After activation of the plugin I can see the cron job to be scheduled for the "next run" at the desired time and the counter is counting down. Unfortunately, the cron job only triggers if a user is browsing to at least one page on my site.

    My question: Is there a way to make a cron job fire, even if no users accessing/browsing the site?

    Help is much appreciated as I can't seem to find any references online.

  2. adilali99
    Member
    Posted 4 years ago #

    is there another anti-hack plugin ?

  3. Rahul Sonar
    Member
    Posted 4 years ago #

    you can ask your host to set up a cron for you..

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    @adilali99

    please start your own thread, and provide more details with your question.

  5. forensicdev
    Member
    Posted 4 years ago #

    I am just wondering why WP requires pages to be loaded in order to trigger cron jobs. I understand that the wp-cron.php is called every time a page is viewed, etc. Yet what I don't get is why have the wp_schedule_event() function, if it still requires user interaction with the site. Doesn't seem logical. Maybe I am missing something.

  6. Nectarine Imp
    Member
    Posted 4 years ago #

    @forensicdev:
    a 'real' cron would require a service / demon process running with root access. If you have root access to your host you can set up a real cron (assuming a non-windows server). The WordPress 'cron' reflects the knowledge that many sites have traffic pretty much every hour. So it takes advantage of this and use that to trigger it's activity (since a web server only acts when prompted).

    So, the broken logic is simply because it is trying to work around getting 'root' to setup the crontab.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags