Cron syntax error near unexpected token

T_E*_*M_A 5 php cron syntax-error

Moved the site to another server. Add file statistic.php to the ?ron to perform. Only this Cron that does not like something. Write errors:

/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");
Run Code Online (Sandbox Code Playgroud)

There is my code

<?php
include ("bd.php");

    $result = mysql_query("SELECT MAX(id) FROM statistic_dep",$db);
    $myrow1 = mysql_fetch_array($result);
    $last_id=$myrow1[0];
...
Run Code Online (Sandbox Code Playgroud)

Dir*_*irk 4

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

你的 crontab 应该是这样的:

* * * * * /usr/bin/php -f /path/to/file.php
Run Code Online (Sandbox Code Playgroud)

作为 php 执行脚本的另一种方法是在第一行添加 shebang:

#!/usr/bin/php
<?php ...
Run Code Online (Sandbox Code Playgroud)