John Priestakos
John Priestakos

Reputation: 390

Cron job report error

I got a cron job with the following code:

<?php
require "config.php";
$truncate = $mysqli->query("TRUNCATE rss_feed");

$cars = $mysqli->query("SELECT *,(SELECT title FROM companies WHERE companies.company_id = cars.company_id) AS car_company,(SELECT car_model FROM models WHERE models.model_id = cars.model_id) AS car_model FROM cars, companies WHERE cars.company_id = companies.company_id AND car_active = 'Active' AND rssPost IS NULL ORDER BY datetime DESC");
$result = $cars->num_rows;

if ($result > 0) {
    while ($row_cars = $cars->fetch_array()) {
        $title = $row_cars['car_company'] . ' ' . $row_cars['car_model'] . ' ' . $row_cars['car_cc'];
        $link = '/car.php?id=' . $row_cars['car_id'];
        $description = $row_cars['car_description'];
        $datetime = $row_cars['datetime'];
        $row_car_id = $row_cars['car_id'];

        $insert = $mysqli->query("INSERT INTO rss_feed (title, link, description, datetime) VALUES ('$title','$link','$description','$datetime')");
        $update = $mysqli->query("UPDATE cars SET rssPost='Yes' WHERE car_id = '$row_car_id'");

        if (!$insert) {
            printf("ERROR: %s\n", $mysqli->error);
        }
    }
    printf($result . " cars inserted");
} else {
    printf("No new cars inserted");
}

I've set cPanel to run the php file every 3 hours and i got he error below:

/public_html/system/cron_rss.php: line 1: ?php: No such file or directory
/public_html/system/cron_rss.php: line 2: require: command not found
/public_html/system/cron_rss.php: line 3: syntax error near unexpected token `('
/public_html/system/cron_rss.php: line 3: `$truncate = $mysqli->query("TRUNCATE rss_feed");'

If i run the file through the URL, it works ok without errors. My IDE editor confirms that there is no suspicious code. I got 755 CHMOD for the file.

Upvotes: 1

Views: 182

Answers (2)

Moppo
Moppo

Reputation: 19285

From the first error line it seems that you are not calling the script properly with cron.

Depending on your Host and your possibilities you may try one of these:

Specify the cron entry this way:

* * * * * /usr/bin/php <path_to_your_script> 

Or specify the cron entry this way:

php -q <path_to_your_script>

Or you can try to write this in the first line of your script:

#!/usr/bin/php

You can also check if this this discussion could help:

discussion

Upvotes: 1

dbinns66
dbinns66

Reputation: 791

Try having the cron job use wget or curl to hit the URL

Upvotes: 0

Related Questions