View Full Version : cron trouble (PHP)
compjab 02-28-2006, 11:28 PM I'm trying to setup a cron job with a PHP script I wrote
I'm entering /home/user/public_html/script.php
The cron finds the script and begins to execute it but it doesn't finish sucessfully
Note: the script works perfectly when executed manually
I'm wondering if PHP is not recognized by the cron??
Can anyone interpret the following error (sent to email):
/home/user/public_html/script.php: line 1: ?php
: No such file or directory
/home/user/public_html/script.php: line 2:
: command not found
/home/user/public_html.script.php: line 3:
syntax error near unexpected token `('
/home/user/public_html/script.php: line 3:
`//function Email($email) {
'
Yes, I am commenting out a function within this script (for testing purposes)
Should the script be moved? Anything? Any help would be appreciated!
scooterh 03-01-2006, 12:13 AM can you paste exactly what you have in cron? and how are you calling it php -q -f /path/to/filename.php?
Scooter
ThatScriptGuy 03-01-2006, 12:44 AM You can't just put /path/to/filename.php. You have to actually tell cron how to execute the file with php -q -f (IIRC)
EDIT: Wow, didn't even see Scooter's post above mine.
Kevin
Mark S 03-01-2006, 12:54 AM there are a couple ways you could do this.
1) Tell cron to do "php file.php <php-options>"
Or...
2) Do a "which php" (from a SSH prompt) and use the output from that and add the following to the top if your .php file, like "#!/path/to/php/bin". Then, tell cron to do "./file.php"
I hope the above information helped some, feel free to post any questions regarding the information above, I will gladly help you.
compjab 03-01-2006, 03:42 PM Tell cron to do "php file.php <php-options>"
You have to actually tell cron how to execute the file with php -q -f (IIRC)
I'm using cPanel as an interface to the cron
The only thing I've entered in cPanel is path/to/file.php - what else should I put in there? where?
ThatScriptGuy 03-01-2006, 03:44 PM You put exactly what we've told you. In the path, put
php -options /path/to/filename.php
Kevin
compjab 03-01-2006, 03:55 PM I think the problem is that I don't know what the "options" consist of/ stanf for... Is there a place to find a list of options?
Additionally, I chmod the file to 777
Is this okay?
ThatScriptGuy 03-01-2006, 04:55 PM It just needs to be 755. At first just try php /path/to/filename. Options aren't always needed.
Kevin
Burhan 03-02-2006, 02:47 AM -q is needed, otherwise PHP will spit out the HTML headers too (which are not needed on the cli).
rich w 03-02-2006, 07:41 AM Don't forget to surpress all functions when you are done using an @ character, else if one fails, you'll get a load of errors in your inbox if you specified an email address, as well as in the error log.
compjab 03-02-2006, 07:55 PM -q is needed, otherwise PHP will spit out the HTML headers too (which are not needed on the cli).
I don't have any HTML in the script accept where the script sends an email to system users >>> Should I still add -q??? What is -q? What are these options? Where can I find a list of them?
What is the cli?
compjab 03-02-2006, 07:57 PM Don't forget to surpress all functions when you are done using an @ character, else if one fails, you'll get a load of errors in your inbox if you specified an email address, as well as in the error log.
When I'm done with what? Where should the @ character go?
This script only knows of functions that it actually uses (i.e., I don't include 'functions.php' anywhere... functions are within this script.. I am commenting out one function with "//" before every line for testing purposes..
arkin 03-02-2006, 08:58 PM In cpanel simply add this as a cron job.
"php -q -f /home/file/crontab.php"
Any errors im assuming will be sent to your default address.
Try it.
riquelme 03-03-2006, 11:58 AM "php -q -f /home/file/crontab.php"
shall i mention, in case you dont know, that you should change /home/file/ by the doc your file is in :
riquelme 03-03-2006, 11:58 AM sorry double posted; quick reply bugged!
arkin 03-03-2006, 12:57 PM Also, I've found when using cPanel its important to use double quotes or single quotes and set the reply (echo) of your PHP script to NULL or something.
I was using a mailing script and it would email me every time the php script parsed because it echo'd a bunch of crap that the debugger thought was an error.
Philco 03-04-2006, 07:07 AM I`ve also found that if the script you are trying to execute with cron is in a password protected directory it will not run.
I guess it may be possible to pass the neccessary username and password in the cron but I have not tried.
Philco
rich w 03-04-2006, 07:10 AM I`ve also found that if the script you are trying to execute with cron is in a password protected directory it will not run.
I guess it may be possible to pass the neccessary username and password in the cron but I have not tried.
Philco
I don't know if its possible to call http:// pages instead of ones in your directory, but you could try this:
http://yourusername:yourpassword@yourdomain.com/securearea/yourcronpage.php
|