tags:

views:

108

answers:

4

What should be given as the url to the script while adding it to cron scheduler.
The script is at domain.com/scripts/script.php
PS:I am using cPanel

A: 

none of these. but full absolute path from the root of the filesystem. you can see that path with this code

echo __FILE__;
Col. Shrapnel
hmmm... well then the path is not the problem. I'd already given it correct. But the script ain't called by cron. Do you know what the reason could be?
shyam
@shyam a programming is slightly different job from fortune telling or telepathy. One sitting in their chair thousands miles from your server **cannot** know anything of reasons. It is programmer's own job to **debug** and find the reasons. What path you "already given"? /public_html/ one? That one is wrong for sure
Col. Shrapnel
@Col. Shrapnel: Nope. I'd used the complete path, ie, `/home/...`, which is the same as output by `echo __FILE__;` . And there is no error in the script - I'm now using a 2 line script to test. I was wondering if I've to do anything more while adding a cron job. Currently I've added the job to run every minute (for testing ofcourse), and the command as `/home/user/php /home/user/public_html/scripts/script.php`. I added the url to php binary now, but it is not working now, and did not without it.
shyam
@shyam there is no urls in the filesystem. Hope you meant a path. But where did you look for errors? to make errors visible you have to either set `log_errors` and `error_log` directives in the php file or use piping, redirecting script output to some file. Make sure that all filenames used by this script also have full absolute paths
Col. Shrapnel
@Col. Shrapnel: I tried running the script manually to check if it's working and I've also added `log_errors` and `error_log`. And like I said the script is just some lines now, so if it's run there should be an output. But my assumption is that it ain't run by cron. So I think there could be a problem in the way I added the job (I did it by using cPanel's interface and not thru command). Here's what it looks like: `0 * * * * /home/domainname/php /home/domainname/public_html/scripts/script.php`
shyam
I found the solution.. had to add `#!/usr/bin/php` at the top of the script. Thanks to @private_meta
shyam
oh I thought were asking about path to your script, not to php interpreter.
Col. Shrapnel
of course I was asking about the path to the script. But I'd got it right right after your answer. But the real problem was not including the path to the interpreter - which I did not know I had to until @private_meta mentioned it.
shyam
+2  A: 

Here's a copy / paste out of one of the cron jobs that I run:

00 7 * * 1,2,3,4,5 /usr/local/bin/php /home/processing/process.php

You must use the absolute path to the PHP binary as well as the absolute path to the script itself.

Ian P
I've never needed the absolute path to the PHP binary.
ceejayoz
If you start your script with #!/usr/local/bin/php, then you don't need it, but it's generally a good practice to include it.
Ian P
+2  A: 

If you add the line

#!/usr/bin/php

to the beginning of your file (use 'which php' to find out your actual directory) and change the file mod to "executable", you should be able to run it just by calling like your second choice,

/public_html/scripts/script.php

I hope that works for you.

private_meta
this seem to work. Thanks a lot!!
shyam
A: 

I had the habit of changing directory cd /var/www/vhosts/somesite.com/httdocs before running script with /usr/bin/php -f ./scriptname.php 2>&1 all in the same line on crontab.

I redirect the error output to get notified by email in case an execution error occured.

From crontab :

[email protected]
*       *       *       *       *       cd /var/www/vhosts/domain.com/httpdocs/; /usr/bin/php -f testmail.php 2>&1
Benoit
Edited first answer.
Benoit