0

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

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

I've never needed the absolute path to the PHP binary.
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.
0

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

echo __FILE__;

8 Comments

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 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: 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 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: 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
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.