Hi Folks,
I'm trying to call a php script via cron:

so I edit the crontab and add (for example)

#Test
10 12 26 2 * /usr/bin/php /var/www/html/intranet/tools/updateCIRenewalDates.php

and the PHP file:


<?php
   define("LIBPATH", "/export/Library/");
   include( LIBPATH . "db.inc");

   $insert = "";
   $connection = @ mysql_connect($hostName, $username, $password) or die("Cannot connect");
   mysql_select_db("mydb", $connection) or die(mysql_error());

   $insert = mysql_query("BEGIN;", $connection);

   $query = "select * from Domain where D_Name = 'robtest.ie'";
   $result = mysql_query ($query, $connection);
   if(!$result){
      echo "Some text to be emailed by Cron if there's an error.\n";
   }
   else{
      echo "A Success Message.\n";
   }

   $insert = mysql_query("COMMIT;", $connection);

   mysql_close($connection);

?>

However when I test it by running the script directly from the command line:

/usr/bin/php /var/www/html/intranet/tools/updateCIRenewalDates.php

I get the horrible:

PHP Warning:  Cannot open 'extra/browscap.ini' for reading in Unknown on line 0
Content-type: text/html

But the correct value prints to the screen - that the select went ok
.
So why would the script be looking for this file(which don't exist) when I don't refer to it anywhere?

I'm running this on a red hat box, and am using php 4.
thanks!
Robin.

    Right - I've been told at work that whenever you come across a browscap.ini problem just uncomment its reference in the php.ini file...so I suppose that's sorted. (even though it's a strange way to fix things?)

    Any ideas about the:

     Content-type: text/html
    
    ~
    

    bits? Why is this showing?

      You might want to look in the db.inc include file to see what it might be doing (and any other files it may include).

        Hi there,

        db.inc just contains 2 functions, (which aren't called in this script), and the db connection values for the $hostName, $databaseName, $username and $password variables used in my file. No other files are included by this script.

        On a separate note - I needed to manually set the autocommit value for mysql via:
        $insert = mysql_query("SET AUTOCOMMIT = 0;");

        since our db had this enabled, which would mean every insert would get commited once successful, and that code like this:

        $insert = mysql_query("BEGIN;", $connection);
        to start transactions wouldn't do anything.

        Something to watch out for in the future!!
        Robin.

        <edit>The tilda character was at the end of the db.inc file, so removing that removes the ~
        So just the Content-type: text/html bit to explain away and its done!
        </edit>

          Hi Folks,
          I gave up trying to figure it out - and used CURL instead:

          So my cron listing now looks something like this:
          10 00 1 curl -G <my URL>/updateCIRenewalDates.php;

          Tests seem to show it runs ok without any mysterious text appearing 8-)
          Robin.

            Write a Reply...