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

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

    2. <legend id='TJFSe'><style id='TJFSe'><dir id='TJFSe'><q id='TJFSe'></q></dir></style></legend>

      • <bdo id='TJFSe'></bdo><ul id='TJFSe'></ul>
      1. <tfoot id='TJFSe'></tfoot>

        如何编写 PHP cron 脚本?

        时间:2023-08-18
        • <bdo id='Z6pJa'></bdo><ul id='Z6pJa'></ul>
            <tfoot id='Z6pJa'></tfoot>
          • <small id='Z6pJa'></small><noframes id='Z6pJa'>

              <tbody id='Z6pJa'></tbody>

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

                  <i id='Z6pJa'><tr id='Z6pJa'><dt id='Z6pJa'><q id='Z6pJa'><span id='Z6pJa'><b id='Z6pJa'><form id='Z6pJa'><ins id='Z6pJa'></ins><ul id='Z6pJa'></ul><sub id='Z6pJa'></sub></form><legend id='Z6pJa'></legend><bdo id='Z6pJa'><pre id='Z6pJa'><center id='Z6pJa'></center></pre></bdo></b><th id='Z6pJa'></th></span></q></dt></tr></i><div id='Z6pJa'><tfoot id='Z6pJa'></tfoot><dl id='Z6pJa'><fieldset id='Z6pJa'></fieldset></dl></div>
                • 本文介绍了如何编写 PHP cron 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果这是一个愚蠢的问题,我很抱歉,但实际上我不知道.

                  I'm sorry if this is a silly question, but in reality I have no clue.

                  我编写了这个应用程序来压缩文件并将文件从客户端的 PC 移动到主 PC.
                  它作为网页工作得很好.这是在几乎没有指导和规范文档的情况下完成的.
                  因此,正如命运所愿,它应该是一个通过调用

                  I wrote this app to compress and move files from a client's PC to a master PC.
                  It works well as a web page. This was don with little guidance and no spec doc.
                  So as fate would have it, it was supposed to be a cron job which would run by calling

                  *****runScript.php

                  所以我不知道执行将或应该以什么顺序进行.

                  So I don't know in which order the execution will or should take place.

                  我使用了 2 个 AJAX 调用来调用脚本中的方法,但仅将文件作为脚本运行就有点不同了.

                  I used 2 AJAX calls to call methods in the script, but just running the file as a script is n bit different.

                  有人可以指导我吗?

                  例如是否有首先调用的 MAIN 方法.如果是这样,那么我可以从那里指导脚本.

                  e.g. is there a MAIN method that will be called first. and if so, then I can guide the script from there.

                  更新

                  答案真的很有帮助,但是php文件会受到什么影响呢?@Ole Haugset 提到我应该调整它,所以使用 $_GET 变量.例如,这已在脚本中通过 if ($_GET["argument"]=='runScript'){} 完成.

                  The answers are really help full, but how would the php file be affected? @Ole Haugset mentioned that I should adapt it so use $_GET vars. This is done in the script already by if ($_GET["argument"]=='runScript'){} for instance.

                  那么将 runScript 附加到脚本调用应该可以正常工作吗?

                  So appending runScript to the script call should work fine?

                  例如* * * * * php/path/to/file/runScript.php runScript

                  推荐答案

                  将 PHP 脚本作为 cron 作业运行没有问题.您需要做的是在文件系统中提供脚本文件的完整路径,并使用命令 php 告诉 Linux 运行该文件的程序.

                  There are no problems running a PHP script as a cron job. What you need to do is provide the full path in the filesystem to the script file, and use the command php to tell Linux what program to run the file with.

                  示例:

                  */5 * * * * php /var/www/vhosts/statistikk/cron/getLastArticleFromIntranet.cron.php >> /var/www/vhosts/statistikk/cron/LOG.txt 2> /dev/null
                  

                  此脚本将每 5 分钟运行一次,每周的所有天都如此.无论 PHP 脚本回显/打印出什么,都将存储到 LOG.txt 文件中,以便我可以监控脚本事件.

                  This script will run every 5 minutes, all days of the week. Whatever the PHP-script echoes / prints out, will be stored to the LOG.txt file so that I can monitor the scripts events.

                  在将命令放入 cronjobs 之前,尝试只在 shell 中运行该命令以确保它有效.

                  Try running just the command in your shell before putting it in the cronjobs to make sure it works.

                  但是,您说您通常使用 AJAX 调用来调用此脚本.使用 cronjob 将无法做到这一点.我假设您使用 AJAX 传递脚本需要的一些 $_POST 元素.因此,您需要做的就是调整脚本以允许 $argv 参数,并将它们添加到 crontab 作业中,或者简单地制作一个在运行之前不需要任何给定参数的脚本.

                  However, you say that you normally call this script with a AJAX call. This will not be possible to do with a cronjob. I assume you use AJAX to pass along some $_POST-elements that the script needs. So what you have to do is either adapt the script to allow $argv parameters as well, and add them to the crontab job, or simply make a script which does not need any given parameters before it runs.

                  如果您要调整脚本以支持 $argv 参数,请遵循 Stack Overflow 上已有的关于向作业添加参数的答案:

                  If you are going to adapt your script to support $argv parameters, follow the answer already existing on Stack Overflow about adding parameters to the job:

                  如何使用cron选项卡中的参数

                  我只想从下面的答案中添加到我的答案中.要在 Linux 中编辑您的 crontab 作业,您只需使用命令 crontab -e.

                  I'd just like to add to my answer as from the answer below. To edit you crontab jobs in Linux you can simply use the command crontab -e.

                  这是需要填写的每个必填参数的描述.

                  This is the description of each required param that needs to be filled.

                  *     *     *   *    *        command to be executed
                  -     -     -   -    -
                  |     |     |   |    |
                  |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
                  |     |     |   +------- month (1 - 12)
                  |     |     +--------- day of        month (1 - 31)
                  |     +----------- hour (0 - 23)
                  +------------- min (0 - 59)
                  

                  这篇关于如何编写 PHP cron 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 PHP 获取在服务器上运行的 PHP 进程列表 下一篇:如何从网络在 yii2 中运行控制台命令

                  相关文章

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

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

                    1. <small id='YoZyD'></small><noframes id='YoZyD'>

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