Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run php script automatically

Tags:

php

i have a php script that should be run automatically every day. as the php script is run on a request,how can i do it? is there any way else using cronjob task?

like image 884
hd. Avatar asked Dec 07 '10 07:12

hd.


People also ask

How do I run a PHP script in Powershell?

Open powershell and type c:\php\php.exe -h , you will get the php help output. Yay you are up and running, whoot. Type env into os search (cortana) and select environmental variables. Now you can run php in powershell with php ( php -h to test).


1 Answers

Two options:

  1. Use crontab demon
  2. Hire a worker and make him open script in a browser every 24 hours

The choice is yours :)

To use crontab, type crontab -e in console, the text file opens. Add a line at the end:

0 0 * * * /usr/bin/php /var/www/mysite/httpdocs/daily_stats.php

Where:

0 0 * * * - run every day at 00:00

/usr/bin/php -path to your PHP (can be determined by which php command)

/var/www/mysite/httpdocs/daily_stats.php - path to your PHP script

if which php outputs nothing, install PHP cli by running:

sudo aptitude install php5-cli 

Good luck!

like image 63
Silver Light Avatar answered Sep 23 '22 07:09

Silver Light