Php Cron Job Problem

by 8 replies
10
I have set up a simple php page on my site to do
some everyday mysql database tasks for updating
the site.

I have run the script from a browser window and it works
however I tried doing a cron and I am not getting an email
to tell me the cron has been done and looking at the site it
looks like it hasn't been used.

I have tried both of these in my cron set up:

php -q /home/XXXXXX/public_html/cron_XXXXXX.php > /dev/null

/usr/bin/GET http://www.XXXXXXXX.com/cron_XXXXXX.php

I set the cron job to run at:

0 minutes
every other hour
every day
every month
every weekday

Niether appear to be working.

This is a short excert from the script:

<?php
include 'system/config.php';
include 'system/opendb.php';

mysql_query("UPDATE `XXXXXX`.`XXXXX` SET `intCategory` = '131' WHERE `intAuthorId` =39930
AND `intStatus` =0")
or die(mysql_error());

mysql_query("DELETE FROM `XXXXXX`
WHERE `textArticleText` LIKE CONVERT( _utf8 '%www.%'
USING latin1 )
COLLATE latin1_swedish_ci
or die(mysql_error());

include 'system/closedb.php';
?>

As I say the script works OK from a browser window so has anyone any idea
what I may be doing wrong.

Any help much appreciated.

Thanks

Terry
#programming #cron #job #php #problem
  • Since your script is publicly accessible, here's an option for your cron command:
    lynx -dump http://www.somedomain.com/cron.php

    That will open the page using the lynx browser on the server, just as if it was a person viewing the page.

    If that still doesn't do it, then perhaps the question is whether or the cron service is actually running.

    -Ryan
    • [ 1 ] Thanks
    • [1] reply
    • Thanks RJP

      That seems to be working as I am now getting an email
      message from cron daemon.

      The email message is blank, would that be correct?

      Many thanks for your help.

      Terry
      • [1] reply
  • The reason your original cronjob wasn't working is because of the "include" command. The path is different when running under cron. If you want it to work without lynx just replace the "include" commands with the actual content, or specify the correct path.
  • use another cron syntax
  • [DELETED]
  • Banned
    [DELETED]
  • use hostgator as a webhost! they provide accurate assistant when it comes to cron job!
  • In your cron, be sure you are running the right php, check your hosting's recommended php to use.

    also you can cd to the folder before executing the script, this will make your includes correct again

    * * * * * * * cd /path/to/script; /usr/bin/php myscript.php >/dev/null 2>&1

Next Topics on Trending Feed