Search code examples
phpunixbatch-fileat-job

Unix 'at' command via PHP to run single function


Is it possible to schedule a single php function to run at a specific time in the future using the Unix 'at' command? If so how would this be done?

Also is this the best way to handle scheduling a single function to run at a later date?


Solution

  • Sure, 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 is perhaps better to call a file which may contain multiple commands

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