• <legend id='kd4Qb'><style id='kd4Qb'><dir id='kd4Qb'><q id='kd4Qb'></q></dir></style></legend>

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

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

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

    1. <tfoot id='kd4Qb'></tfoot>

        PHP 可以检测它是从 cron 作业还是从命令行运行?

        Can PHP detect if its run from a cron job or from the command line?(PHP 可以检测它是从 cron 作业还是从命令行运行?)

            • <i id='3m6Ul'><tr id='3m6Ul'><dt id='3m6Ul'><q id='3m6Ul'><span id='3m6Ul'><b id='3m6Ul'><form id='3m6Ul'><ins id='3m6Ul'></ins><ul id='3m6Ul'></ul><sub id='3m6Ul'></sub></form><legend id='3m6Ul'></legend><bdo id='3m6Ul'><pre id='3m6Ul'><center id='3m6Ul'></center></pre></bdo></b><th id='3m6Ul'></th></span></q></dt></tr></i><div id='3m6Ul'><tfoot id='3m6Ul'></tfoot><dl id='3m6Ul'><fieldset id='3m6Ul'></fieldset></dl></div>

              <legend id='3m6Ul'><style id='3m6Ul'><dir id='3m6Ul'><q id='3m6Ul'></q></dir></style></legend>
                <bdo id='3m6Ul'></bdo><ul id='3m6Ul'></ul>
                <tfoot id='3m6Ul'></tfoot>

                <small id='3m6Ul'></small><noframes id='3m6Ul'>

                    <tbody id='3m6Ul'></tbody>
                • 本文介绍了PHP 可以检测它是从 cron 作业还是从命令行运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在寻找 PHP 的方法来检测脚本是从 shell 上的手动调用运行的(我登录并运行它),还是从 crontab 条目运行.

                  I'm looking for way to PHP to detect if a script was run from a manual invocation on a shell (me logging in and running it), or if it was run from the crontab entry.

                  我有各种用 php 编写的维护类型脚本,我已将它们设置为在我的 crontab 中运行.有时,我需要提前手动运行它们,或者如果出现故障/损坏,我需要运行几次.

                  I have various maintenance type scripts written in php that i have set to run in my crontab. Occasionally, and I need to run them manually ahead of schedule or if something failed/broken, i need to run them a couple times.

                  这样做的问题是,我在任务中也设置了一些外部通知(发布到 Twitter、发送电子邮件等),我不想在每次手动运行脚本时发生这些通知.

                  The problem with this is that I also have some external notifications set into the tasks (posting to twitter, sending an email, etc) that I DONT want to happen everytime I run the script manually.

                  我使用的是 php5(如果重要的话),它是一个相当标准的 linux 服务器环境.

                  I'm using php5 (if it matters), its a fairly standard linux server environment.

                  有什么想法吗?

                  推荐答案

                  与其检测脚本何时从 crontab 运行,不如手动运行脚本更容易检测.

                  Instead of detecting when the script is run from the crontab, it's probably easier to detect when you're running it manually.

                  当您从命令行运行脚本时,会设置很多环境变量(在 $_ENV 数组中).这些将根据您的服务器设置和登录方式而有所不同.在我的环境中,手动运行脚本时设置了以下环境变量,而从 cron 运行时不存在这些环境变量:

                  There are a lot of environment variables (in the $_ENV array) that are set when you run a script from the command line. What these are will vary depending on your sever setup and how you log in. In my environment, the following environment variables are set when running a script manually that aren't present when running from cron:

                  • 期限
                  • SSH_CLIENT
                  • SSH_TTY
                  • SSH_CONNECTION

                  还有其他的.例如,如果您始终使用 SSH 访问该框,那么以下行将检测脚本是否从 cron 运行:

                  There are others too. So for example if you always use SSH to access the box, then the following line would detect if the script is running from cron:

                  $cron = !isset($_ENV['SSH_CLIENT']);

                  这篇关于PHP 可以检测它是从 cron 作业还是从命令行运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    <bdo id='RhuFC'></bdo><ul id='RhuFC'></ul>
                    <tfoot id='RhuFC'></tfoot>
                  • <small id='RhuFC'></small><noframes id='RhuFC'>

                      <tbody id='RhuFC'></tbody>

                        1. <legend id='RhuFC'><style id='RhuFC'><dir id='RhuFC'><q id='RhuFC'></q></dir></style></legend>

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