Timer in PHP calling Function

Asked

Viewed 584 times

-1

Someone has a simple example of a timer on PHP, to call a function at each predetermined time. For example, to check if a certain time or date/time has already arrived.

  • 1

    Post the code you’ve done so far!

  • 1

    Depending on your goal it is not possible, as PHP needs a trigger to run. Because without running a script a script does nothing, it would need the timer to be done either in crontab, or with javascript. Why in pure PHP would need refresh to check the weather

  • Could you better contextualize your question?

  • 1

    It depends, you want to run something in the background, or you want when the time comes, php to send something to the browser?

  • It is for several functions, such as updating a date/time, mounting a countdown counter, checking if the database has been changed.

  • 1

    @Orlandofmc which server ?

Show 1 more comment

1 answer

1

You can make use of the crontab, just set the time and the file php what to call; for example:

*  *  * * *   root    php /path/file.php >/dev/null 2>&1

This script will run every minute, and every day, by the root user, below I will leave a self explanatory image of the use of cromtab;

The >/dev/null 2>&1 plays all the way out of limbo, simple way of not printing on the screen returns from the script.

CROMTAB

There are other ways to use, for example with Laravel;

  • One observation: if that is the answer, the question is duplicated. There are already several on the site talking about crontab and task scheduler (note that the question has been abandoned since 2016).

  • Yes I realized after responding, I saw that Avia been updated today, with respect to crontab I see no more practical form than this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.