我用下面的代码cron作业: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");
}
我设置的cPanel运行PHP文件每3个小时,我得到了他以下错误:
/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");'
如果我通过URL运行该文件,它可以正常工作,没有错误。我的IDE编辑器确认没有可疑代码。我得到了文件的755 CHMOD。
好像'PHP -q'在首位丢失。你的答案清除了这一点。我会在2h检查一下,cron会再次运行。 –
只是为了确认,'php -q'是个问题。一切运作良好。谢谢你们 –