• <bdo id='2fADg'></bdo><ul id='2fADg'></ul>
    1. <small id='2fADg'></small><noframes id='2fADg'>

      <i id='2fADg'><tr id='2fADg'><dt id='2fADg'><q id='2fADg'><span id='2fADg'><b id='2fADg'><form id='2fADg'><ins id='2fADg'></ins><ul id='2fADg'></ul><sub id='2fADg'></sub></form><legend id='2fADg'></legend><bdo id='2fADg'><pre id='2fADg'><center id='2fADg'></center></pre></bdo></b><th id='2fADg'></th></span></q></dt></tr></i><div id='2fADg'><tfoot id='2fADg'></tfoot><dl id='2fADg'><fieldset id='2fADg'></fieldset></dl></div>
      <legend id='2fADg'><style id='2fADg'><dir id='2fADg'><q id='2fADg'></q></dir></style></legend>
      <tfoot id='2fADg'></tfoot>

      1. 为什么 crontab 不执行我的 PHP 脚本?

        Why is crontab not executing my PHP script?(为什么 crontab 不执行我的 PHP 脚本?)
          <tbody id='MNU3G'></tbody>

            <small id='MNU3G'></small><noframes id='MNU3G'>

            <legend id='MNU3G'><style id='MNU3G'><dir id='MNU3G'><q id='MNU3G'></q></dir></style></legend>
            <i id='MNU3G'><tr id='MNU3G'><dt id='MNU3G'><q id='MNU3G'><span id='MNU3G'><b id='MNU3G'><form id='MNU3G'><ins id='MNU3G'></ins><ul id='MNU3G'></ul><sub id='MNU3G'></sub></form><legend id='MNU3G'></legend><bdo id='MNU3G'><pre id='MNU3G'><center id='MNU3G'></center></pre></bdo></b><th id='MNU3G'></th></span></q></dt></tr></i><div id='MNU3G'><tfoot id='MNU3G'></tfoot><dl id='MNU3G'><fieldset id='MNU3G'></fieldset></dl></div>
          1. <tfoot id='MNU3G'></tfoot>
              <bdo id='MNU3G'></bdo><ul id='MNU3G'></ul>

                  本文介绍了为什么 crontab 不执行我的 PHP 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经构建了一个 php 文件来检查一些结果,因此我需要设置一个 cronjob.

                  I have built one php file to check some result, so that I need to setup a cronjob.

                  我设置了每 30 分钟运行一次,以便发送结果.但是,我不知道为什么我的 crontab 没有每 30 分钟运行一次.

                  I set one to run every 30 minute, so that the results will be send. However, I don't know why my crontab did not run after every 30 minute.

                  这是我设置 crontab 的方法:

                  Here is how I set the crontab:

                  */30 * * * * php /var/www/html/result.php
                  

                  我已经确认我的文件目录是正确的.我不确定的是关于计时部分:是否可以使用 */30 * * * *30 * * * * ?我设置了 */30 * * * * 并没有工作.

                  I have confirmed my file directory is correct. What I not sure is about the timing part: isn't it possible to use */30 * * * * or 30 * * * * ? I set */30 * * * * and did not work.

                  推荐答案

                  Given

                  */30 * * * * php /var/www/html/result.php
                  

                  它不工作的原因有多种可能:

                  There are multiple possibilities why it is not working:

                  1. 首先检查php/var/www/html/result.php 是否简单执行很重要.这是必需的.但不幸的是,完成这并不意味着问题就解决了.

                  1. First of all it is important to check if the simple execution of php /var/www/html/result.php. This is required. But unfortunately, accomplishing this does not mean that the problem is solved.

                  必须添加 php 二进制文件的路径.

                  The path of the php binary has to be added.

                  */30 * * * * php /var/www/html/result.php
                  

                  改成

                  */30 * * * * /usr/bin/php /var/www/html/result.php
                  

                  或来自 which php 的任何内容.

                  or whatever coming from which php.

                  检查脚本对运行 crontab 的用户的权限.

                  Check the permission of the script to the user running the crontab.

                  赋予文件执行权限:chmod +x file.并确保 crontab 是由有权执行脚本的用户启动的.还要检查用户是否可以访问文件所在的目录.

                  Give execution permission to the file: chmod +x file. And make sure the crontab is launched by a user having rights to execute the script. Also check if the user can access the directory in which the file is located.

                  为了更安全,还可以在脚本顶部添加php路径,如:

                  To be safer, you can also add the php path in the top of the script, such as:

                  #!/usr/bin/php -q
                  <?php
                  
                   ...
                  
                  ?>
                  

                • 确保用户有权使用 crontab.检查他是否在 /etc/cron.d/deny 文件中.另外,做一个基本的测试,看看是crontanb还是php的问题.

                • Make sure the user has rights to use crontab. Check if he is in the /etc/cron.d/deny file. Also, make a basic test to see if it is a crontanb or php problem.

                  * * * * * touch /tmp/hello
                  

                • 将脚本的结果输出到日志文件,如牛伟建议.

                  */30 * * * * /usr/bin/php /var/www/html/result.php > /tmp/result
                  

                • 使用-f选项来执行脚本:

                  */30 * * * * /usr/bin/php -f /var/www/html/result.php > /tmp/result
                  

                • 确保 crontab 中的格式正确.例如,您可以使用网站 Crontab.guru.

                  <小时>

                  总结,可能的原因有很多.其中之一应该可以解决问题.


                  To sum up, there are many possible reasons. One of them should solve the problem.

                  这篇关于为什么 crontab 不执行我的 PHP 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!
                • 相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  1. <i id='fpbT6'><tr id='fpbT6'><dt id='fpbT6'><q id='fpbT6'><span id='fpbT6'><b id='fpbT6'><form id='fpbT6'><ins id='fpbT6'></ins><ul id='fpbT6'></ul><sub id='fpbT6'></sub></form><legend id='fpbT6'></legend><bdo id='fpbT6'><pre id='fpbT6'><center id='fpbT6'></center></pre></bdo></b><th id='fpbT6'></th></span></q></dt></tr></i><div id='fpbT6'><tfoot id='fpbT6'></tfoot><dl id='fpbT6'><fieldset id='fpbT6'></fieldset></dl></div>
                      <tbody id='fpbT6'></tbody>

                    <small id='fpbT6'></small><noframes id='fpbT6'>

                      <legend id='fpbT6'><style id='fpbT6'><dir id='fpbT6'><q id='fpbT6'></q></dir></style></legend>

                        <bdo id='fpbT6'></bdo><ul id='fpbT6'></ul>

                            <tfoot id='fpbT6'></tfoot>