running a php script in a cronjob

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rshand
Forum Newbie
Posts: 3
Joined: Tue Feb 16, 2010 10:23 pm

running a php script in a cronjob

Post 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
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: running a php script in a cronjob

Post 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
 
rshand
Forum Newbie
Posts: 3
Joined: Tue Feb 16, 2010 10:23 pm

Re: running a php script in a cronjob

Post 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)
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: running a php script in a cronjob

Post 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
rshand
Forum Newbie
Posts: 3
Joined: Tue Feb 16, 2010 10:23 pm

Re: running a php script in a cronjob

Post 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?
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: running a php script in a cronjob

Post 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.
Post Reply