Results 1 to 5 of 5

Thread: Cron & Php

  1. #1
    Join Date
    Sep 2003
    Montreal, Canada

    Angry Cron & Php

    PHP Code:

    include 'PrevNext_class.php';

    $db = new PrevNext_class;
    $db->dbname 'wojtek_cooking';
    $db->offset 'recipe';
    $db->limit 1;
    $db->number_type 'number';

    $db->execute("SELECT * from recipes ORDER BY RAND()");

    //print "<center><h3>Random Recipe</h3>";

    while($myrow mysql_fetch_array($db->sql_result))

    //echo "<br><br>Comment1: $myrow[0]";
    //echo "<br><br>Comment2: $myrow[1]";
    //echo "<br><br>Comment3: $myrow[2]";
    //echo "<br><br>Comment4: $myrow[3]";
    //echo "<br><br>Comment5: $myrow[4]";
    //echo "<br><br>Comment6: $myrow[5]";
    //echo "<br><br>Comment7: $myrow[6]";

    $string="<a href='".$myrow[0]."'><table border=\"0\" width=\"100%\" id=\"table5\" onMouseover=\"'#DBD9A9';\" onMouseout=\"'';\"><tr><td align=\"center\" width=\"33%\"><h2 align=\"right\"><b>&gt;&nbsp; </b></h2></td><td align=\"center\" width=\"33%\">$myrow[1]</td><td align=\"center\" width=\"33%\"><h2 align=\"left\"><b>&lt;</b></h2></td></tr><tr><td colspan=\"3\"><u>Description:</u><br>$myrow[5]</td></tr></table></a>";


    $fp fopen("recipe24h.txt""w");

    This script selects one entry from the database and writes it to a .txt file
    Set to run once per hour (24 times / day)
    I include that .txt on the index, thus 1 random entry is shown every hour

    If i run it via a browser, it works fine, but with cron, it emails me an error log:
    /home/wojtek/public_html/RandomRecipe.php: line 1: ?php: No such file or directory
    /home/wojtek/public_html/RandomRecipe.php: line 3: include: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 11: =: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 13: -: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 15: -: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 17: -: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 19: -: command not found
    /home/wojtek/public_html/RandomRecipe.php: line 21: syntax error near unexpected token `('
    /home/wojtek/public_html/RandomRecipe.php: line 21: ` $db->connection('localhost','xxxxxxxxxxx','yyyyyyyyyyyyy');'
    What is wrong??

  2. #2
    Join Date
    Jul 2001
    Glasgow, Scotland
    It seems that it isn't parse as php at all...
    My development blog - (un)Interesting codesnippets and the occational code-related rant!

  3. #3
    What command are you using in cron to call the script?

    Try (if php is some place else, then put the real path)

    /usr/bin/php -q /home/wojtek/public_html/$script.php

  4. #4
    Join Date
    Sep 2001
    Clifton Park, NY
    If you don't run the file as an argument to the php binary then you have to specify the binary to use. Make this the first line of the file:

    #!/usr/local/bin/php -q

    If that's not your php location just put in the right one. The -q makes it not spit out stuff you don't want to see.
    John K. Reyes, RHCE, CISSP
    CTO, Inc.

  5. #5
    Join Date
    Sep 2003
    Montreal, Canada
    i found out my problem

    php is installed as an apache module, thus i had to

    lynx -dump

    works fine now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts