Reputation: 1646
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?
Upvotes: 4
Views: 1200
Reputation: 34013
To do that a PHP script would need to be persistent inside the PHP interpreter for some long interval of time.
The best you could do would be to use something like exec
to create the unix command you's use and then call the php
command line version to make it work. Look at Scheduling php scripts for more information.
Upvotes: 0
Reputation: 825
if you want to run it from php script try using exec() function
Upvotes: 1
Reputation: 270609
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
Upvotes: 6