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
running a php script in a cronjob
Moderator: General Moderators
Re: running a php script in a cronjob
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
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
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
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
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
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.