简体   繁体   中英

php function to schedule execution of a task at a certain time

I want to create a web based app, written in PHP that work like a reminder app, so the user enters a line of text and a time to reminded, app gets these two and at the specified time reminds the user. I implemented the program completely, but for scheduling, I have a problem: the program should do other jobs in between setting reminder and reminding user, but the only function that I find that can do something similar is sleep(), but it seems that sleep() is not the best choice because in between setting the reminder and reminding the user, the program could not to do anything.

Is there a function in php that enables scheduling tasks and at the specified time, the PHP program runs the task.

I do not want cron , crontab , scheduled task or any other OS-dependent solution.

It isn't possible to execute a task at specified time in PHP only.

You may create a condition comparing current time with the time the task should be executed and run it on every request, but that doesn't guarantee the execution at the exact time, since there may be no user requests at all.

This is what cron is for.

This is not possible in PHP.

You may check if your host provide a cron-like option (mine provide an URL call scheduling).

Another option, if users are always connected to your web app, is to manage alerts in javascript and/or ajax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM