Page 1 of 1
running a php script in a cronjob
Posted: Tue Feb 16, 2010 10:27 pm
by rshand
I created a php script and it works fine from the shell command prompt:
# ./myscript.php
I then added to a crontab
3 23 * * * /usr/bin/php /var/myfileDirectory/myscript.php
and I can get it to work.
Any ideas?
thanks
Re: running a php script in a cronjob
Posted: Wed Feb 17, 2010 5:58 am
by dejvos
I think you have to use
-q ... so the form could be
Code: Select all
3 23 * * * /usr/bin/php -q /var/myfileDirectory/myscript.php
Re: running a php script in a cronjob
Posted: Wed Feb 17, 2010 7:50 am
by rshand
I tried that thanks. I believe the -q is used only to suppress the output so you don't get an email response every time the cron runs (I wasn't getting the email outputs either)
Re: running a php script in a cronjob
Posted: Wed Feb 17, 2010 8:37 am
by dejvos
I'm not sure about -q but I think that it suppres HTTP headers. Actually I had looked into a man page of /usr/bin/php just before I answared you and I had found no -q ... it's strange but I was used to put the parametr infront of all scripts and it works every time.
If it is not your case try to check the rights. I had a lot of troubles with the permissions because script could be executed under another user than apache or www or which user is common for Apache or other server
Re: running a php script in a cronjob
Posted: Wed Feb 17, 2010 9:12 am
by rshand
Thanks for that. It must be a permission thing. This script is an internal script which pulls a file from a directory renames and then moves it to another directory. I do not want this script to be executed from anyone using a browser. Do you think is causing the problem?
Re: running a php script in a cronjob
Posted: Thu Feb 18, 2010 2:41 am
by dejvos
Yes, it could be. It depends on which user save a data to a directory. If it's via browser it could be a problem because Apache or whatever you use has his its own user and group. So you have to change the permissions.