简体   繁体   English

Cron作业报告错误

[英]Cron job report error

I got a cron job with the following code: 我得到了一个具有以下代码的cron作业:

<?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: 我已经将cPanel设置为每3小时运行一次php文件,但我在下面得到了他的错误:

/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. 如果我通过URL运行文件,则可以正常运行而不会出现错误。 My IDE editor confirms that there is no suspicious code. 我的IDE编辑器确认没有可疑代码。 I got 755 CHMOD for the file. 我的文件是755 CHMOD。

From the first error line it seems that you are not calling the script properly with cron. 从第一个错误行看,您似乎没有使用cron正确调用脚本。

Depending on your Host and your possibilities you may try one of these: 根据您的房东和您的可能性,您可以尝试以下方法之一:

Specify the cron entry this way: 通过以下方式指定cron条目:

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

Or specify the cron entry this way: 或者以这种方式指定cron条目:

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 讨论

尝试让cron作业使用wget或curl来访问URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM