Cron Job Error

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
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Cron Job Error

Post 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.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

What is does the source of your php file have on those lines?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

Code: Select all

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