AssamGuy
AssamGuy

Reputation: 1593

Run cron job to execute a php function after some fixed time

I have read the answer https://stackoverflow.com/questions/1830208/php-cron-job-every-10-minutes#=

I have similar kind of question: I am trying to run a cron job to execute a php function which will delete some fields , after checking some conditions . So I want to know how will I run the function within that php file . Should I add the path like 'http://somename/index.php?do=dlt" or just the function something else

Upvotes: 0

Views: 4487

Answers (2)

k102
k102

Reputation: 8089

1: change your script to use command line parameters instead of _GET: the first argument is in $argv[1] variable

2: create cronjob like this:

*/5 * * * * /usr/bin/php /path/to/script/index.php dlt

note, that you may have to specify full path to php binary (whereis php) and to your script.

3: if there's some include or require - change path to absolute.

Upvotes: 2

Krzysztof
Krzysztof

Reputation: 16150

You can invoke PHP CLI version like php /path/to/file/file.php dlt or by using wget like tool wget http://somename/index.php?do=dlt. In first case you must change your script to use $argv instead of $_GET. In second case it'll work right away, because it'll use http server underneath.

Upvotes: 1

Related Questions