Unix 'at' command via PHP to run a single function

Is it possible to schedule a single php function to run at a specific time in the future with the Unix 'at' command? If so, how to do it?

Is this also the best way to handle scheduling a single function to be launched later?

+4
source share
3 answers

Of course, you can use at or cron and pass the -R flag to PHP to execute the command line:

 # Run phpinfo() at 12:30... echo php -R 'phpinfo();' | at 12:30 

Or it might be better to invoke a file that may contain several commands

 echo 'php /path/to/yourfile.php' | at 12:30 
+6
source

if you want to run it from php script try using exec () function

+1
source

To do this, the PHP script must be constant inside the PHP interpreter for a long period of time.

The best you could do is use something like exec to create the unix command that you are using and then call the php command line version to make it work. See Planning for php scripts for more information.

0
source

Source: https://habr.com/ru/post/1398668/


All Articles