Scalable, Delayed PHP Processing

后端 未结 15 878
长情又很酷
长情又很酷 2020-12-08 01:41

I\'m working on an online PHP application that has a need for delayed PHP event. Basically I need to be able to execute arbitrary PHP code x many seconds (but it could be da

15条回答
  •  醉梦人生
    2020-12-08 02:09

    Have your php script make an exec call to schedule your PHP script to run at the time you need using the command "at"

    exec("at 22:56 /usr/bin/php myscript.php");

    at executes commands at a specified time.

    from the man page:

    At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a spe cific time of day. (If that time is already past, the next day is assumed.) You may also specify midnight, noon, or teatime (4pm) and you can have a time-of-day suffixed with AM or PM for running in the morning or the evening. You can also say what day the job will be run, by giving a date in the form month-name day with an optional year, or giving a date of the form MMDDYY or MM/DD/YY or DD.MM.YY. The specifi cation of a date must follow the specification of the time of day. You can also give times like now + count time-units, where the time-units can be minutes, hours, days, or weeks and you can tell at to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with tomorrow.

    Further, if you need one second time resolution, have your script run at the start of the minute, then just sleep n seconds until it is time to execute.

提交回复
热议问题