Page 1 of 1

Cron Job Error

Posted: Tue Sep 04, 2007 1:11 pm
by icesolid
I am getting an error each time I have my Cron Job run. The error is below:

Code: Select all

/home/capous/public_html/update_webdemo.php: line 1: ?php: No such file or directory
/home/capous/public_html/update_webdemo.php: line 2: syntax error near unexpected token `"localhost",'
/home/capous/public_html/update_webdemo.php: line 2: `mysql_connect("localhost", "username", "username") or die("Could not connect to database.");'
I am running PHP as Apache module, not CGI.

Posted: Tue Sep 04, 2007 1:27 pm
by Begby
What is does the source of your php file have on those lines?

Posted: Tue Sep 04, 2007 1:38 pm
by icesolid

Code: Select all

<?php
mysql_connect("localhost", "username", "password") or die("Could not connect to database.");
mysql_select_db("main") or die("Could not select database.");
Those are the first lines on the document.

Posted: Tue Sep 04, 2007 5:05 pm
by icesolid
It almost seems as if it is not reading my php code correctly.

Is there any statement I need to add in before I start my PHP code.

Posted: Tue Sep 04, 2007 5:22 pm
by VladSun
Try to add this line at the top of you php files:

Code: Select all

#!/bin/php
Just make sure the location of php executable is right ...

Code: Select all

which php
Also make sure these php file are 0755 chmoded.


Another solution is to execute it by:

Code: Select all

php -e path/to/file.php
in your crontabs file.

Posted: Tue Sep 04, 2007 6:07 pm
by icesolid

Code: Select all

php -e path/to/file.php
Worked!