Cron作业PHP脚本错误[重复]

This question already has an answer here:

I had made a cron job with this comment : "/home/username/public_html/cron.php"

My php (cron.php)

    <?php 

    $server = 'localhost';
    $user = 'name';
    $pass = 'password';
    $dbname = 'dbname';

    $conn = new mysqli($server, $user, $pass, $dbname);

    $sql = "Update table;";
    $conn->query($sql);

    $conn->close();
    ?>

and this is the error :

/home/username/public_html/cron.php: line 1: ?php: No such file or directory
/home/username/public_html/cron.php: line 3: =: command not found
/home/username/public_html/cron.php: line 4: =: command not found
/home/username/public_html/cron.php: line 5: =: command not found
/home/username/public_html/cron.php: line 6: =: command not found
/home/username/public_html/cron.php: line 8: syntax error near unexpected token `('
/home/username/public_html/cron.php: line 8: `$conn = new mysqli($server, $user, $pass, $dbname);'

Anyone can help in solving this? thank you.

</div>
douaikuai2715
douaikuai2715 shell不知道如何解释PHP代码。使用php解释器和/或shebang。
大约 4 年之前 回复

1个回答



您的脚本被解释为shell脚本。 要在命令行运行PHP脚本:</ p>

  php /home/username/public_html/cron.php
</ pre>

< p>或者将它添加到文件的顶部并使其可执行:</ p>

 #!/ usr / bin / php 
</ code> </ pre>

(或者PHP可执行文件的路径)</ p>
</ div>

展开原文

原文

Your script is being interpreted as a shell script. To run a PHP script at the command line:

php /home/username/public_html/cron.php

Or add this to the top of the file and make it executable:

#!/usr/bin/php

(or whatever is the path your PHP executable)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐