WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Call function once per day (4 posts)

  1. willx
    Member
    Posted 1 year ago #

    Ok, first of all, I'm looking for something specific like a scheduler or something.

    My problem: I want to run a specific function (lets call it doSomething()) exactly once a day, at night (like 03:00 am).

    I was looking for something like this, and I found the function "wp schedule event". However, in the documentation, it says "The action will trigger when someone visits your WordPress site, if the scheduled time has passed."

    This is not what I want, the function should be called when the scheduled time has passed, regardless of whether or not a visitor visits the website.
    (That's the main reason why I want to run this once at night, cause it will pull data from many locations and put about 70 000 records in my database, I cannot let a visitor wait 2 minutes to load the website, just cause the function is running...)

    Is this possible in WordPress?

  2. willx
    Member
    Posted 1 year ago #

    Nevermind this, apperently the WP-Cron (built-in which wp_schedule_event also uses) makes sure the user isn't slowed down...

  3. maxhodges
    Member
    Posted 1 year ago #

    >apperently the WP-Cron (built-in which wp_schedule_event also uses) makes sure the user isn't slowed down...

    what was your source of that info (if you don't mind sharing!)

  4. maxhodges
    Member
    Posted 1 year ago #

    ah nevermind. thanks for pointing me in the right direction!

    The reason to call wp-cron.php is because some jobs might take more time and the user requesting the WordPress page cannot be made to wait. Calling the wp-cron.php helps keep the WP-Cron function running as a separate process in the background without delaying the page load time for the user. Once the WP-Cron function starts, it continues to run until all the required jobs are completed or until it reaches an execution time as set in the server configuration.

Topic Closed

This topic has been closed to new replies.

About this Topic