意外标记附近的Cron语法错误


Cron syntax error near unexpected token

将站点移动到另一台服务器。将文件statistic.php添加到要执行的Сron中。只有这个克朗不喜欢什么。写入错误:

/home/site/www/statistic.php: line 1: ?php: No such file or directory
/home/site/www/statistic.php: line 2: syntax error near unexpected token `"bd.php"'
/home/site/www/statistic.php: line 2: `include ("bd.php");

这是我的代码

<?php
include ("bd.php");
    $result = mysql_query("SELECT MAX(id) FROM statistic_dep",$db);
    $myrow1 = mysql_fetch_array($result);
    $last_id=$myrow1[0];
...

请确保将脚本作为php脚本而不是bash脚本执行。

你的crontab应该是这样的:

* * * * * /usr/bin/php -f /path/to/file.php

以php形式执行脚本的另一种方法是在第一行中添加一个shebang:

#!/usr/bin/php
<?php ...