I have a php file under php called test.php set to run every 5th minute of the hour. When ever I run the file manually (by going to the web browser and runnint the path) it works fine. But when the cron job tries to run it I get the error message

my cron job is

#### Delete Records
5 * * * * /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

my phpfile is (path : /var/www/html/phpsysinfo/phpfile)

 $sql = mysql_query("DELETE FROM list where status <> 'LEAD'") or die(mysql_error());

and the error that I get is:

/var/www/html/phpsysinfo/phpFile.php: line 1: ?php: No such file or directory
/var/www/html/phpsysinfo/phpFile.php: line 2: syntax error near unexpected token `"dbconnect.php"'
/var/www/html/phpsysinfo/phpFile.php: line 2: `require("dbconnect.php");



You're missing the call to the php binary in your cron, it should look like this

### Delete Records
5 * * * * php -q /var/www/html/phpsysinfo/cronUpdateLeadBucketOnEnergycAlliance.php

Please substitute php with php-cli depending on how the php command line binary is named on your distribution :)

  • 2
    ...you will probably have to specify the path to the php binary too. – David Mackintosh Feb 1 '11 at 15:12
  • only if php is in a location not available in the PATH but yeah, good point :) +1 – lynxman Feb 1 '11 at 15:20
  • ok, strictly speaking you "should" include the path to the php binary so that you are explicit about what you are running and not getting hijacked by something unexpected in the path. – David Mackintosh Feb 1 '11 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.