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

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

      1. 将 php 脚本作为 cron 作业运行 - 超时问题?

        时间:2023-08-17
          <bdo id='5PAkX'></bdo><ul id='5PAkX'></ul>
          • <i id='5PAkX'><tr id='5PAkX'><dt id='5PAkX'><q id='5PAkX'><span id='5PAkX'><b id='5PAkX'><form id='5PAkX'><ins id='5PAkX'></ins><ul id='5PAkX'></ul><sub id='5PAkX'></sub></form><legend id='5PAkX'></legend><bdo id='5PAkX'><pre id='5PAkX'><center id='5PAkX'></center></pre></bdo></b><th id='5PAkX'></th></span></q></dt></tr></i><div id='5PAkX'><tfoot id='5PAkX'></tfoot><dl id='5PAkX'><fieldset id='5PAkX'></fieldset></dl></div>

            <small id='5PAkX'></small><noframes id='5PAkX'>

              1. <tfoot id='5PAkX'></tfoot>
                  <tbody id='5PAkX'></tbody>
                <legend id='5PAkX'><style id='5PAkX'><dir id='5PAkX'><q id='5PAkX'></q></dir></style></legend>
                  本文介绍了将 php 脚本作为 cron 作业运行 - 超时问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写一个 php 脚本,它执行一些后端操作,需要每 8 小时左右运行一次.该脚本需要一段时间才能执行.糟糕的是,我从浏览器中尝试了它,并且在脚本终止之前与服务器的连接很好地重置了.我的问题是 - 如果我直接运行它,即.php -a file.php 作为 cron 作业,执行是否有任何内部时间限制?此脚本可能需要 2-5 分钟才能完成且不能中断.我以前从未这样做过,所以我不确定 php 在运行繁重的脚本时是否有怪癖.

                  I am coding a php script that does some back end stuff and needs to run every 8 hours or so. The script takes a while to execute. For the hell of it, I tried it from my browser and the connection to the server gets reset well before the script terminates. My question is - if I run it directly, ie. php -a file.php as a cron job, are there any internal time constraints on execution? This script may take 2-5 minutes to complete and cannot be interrupted. I've never done this before so I am not sure if php has quirks when running heavy scripts.

                  推荐答案

                  如前所述,CLI 脚本默认没有时间限制.

                  As said before, CLI scripts by default have no time limit.

                  但我还想提一下您的 cron 作业方法的替代方法:
                  您可以从 Web 服务器控制下的 PHP 脚本派生出 CLI PHP 脚本.我已经这样做了很多次.如果您的脚本执行时间长且必须由某些网站用户操作触发(例如,构建一个非常大的存档文件并在文件完成时通过电子邮件发送下载链接),则此功能特别有用.我通常使用 popen() 函数从网络服务器 PHP 脚本派生一个 CLI 脚本.这允许像这样很好地将参数传输到新的脚本实例:

                  But I would also like to mention an alternative to your cron job approach:
                  You can fork a CLI PHP script from a PHP script under webserver control. I have done this many times. It is especially useful if you have a script with long execution time which must be triggered by some website user action (e.g. building a very large archive file and send a download link by email when the file is complete). I usually fork a CLI script from a webserver PHP script using the popen() function. This allows to nicely transfer parameters to the new script instance like this:

                  $bgproc = popen('php "/my/path/my-bckgrnd-proc.php"', 'w');
                  if($bgproc===false){
                    die('Could not open bgrnd process');
                  }else{
                    // send params through stdin pipe to bgrnd process:
                    $p1 = serialize($param1);
                    $p2 = serialize($param2);
                    $p3 = serialize($param3);
                    fwrite($bgproc, $p1 . "
                  " . $p2 . "
                  " . $p3 . "
                  ");
                    pclose($bgproc);
                  }
                  

                  在 CLI 脚本中,您会像这样收到这些参数...

                  In the CLI script you would receive these params like this...

                  $fp = fopen('php://stdin', 'r');
                  $param1 = unserialize(fgets($fp));
                  $param2 = unserialize(fgets($fp));
                  $param3 = unserialize(fgets($fp));
                  fclose($fp);
                  

                  ...并在网络服务器控制下对它们做任何需要很长时间的事情.

                  ...and do anything with them that would take to long under webserver control.

                  这种技术在 *nix 和 Windows 环境中同样有效.

                  This technique works equally well in *nix and Windows environments.

                  这篇关于将 php 脚本作为 cron 作业运行 - 超时问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 IMAP 和 php 将邮件附件下载到特定文件夹 下一篇:Laravel 中的 Cron 作业

                  相关文章

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

                    <tfoot id='5tAIo'></tfoot>

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

                      <small id='5tAIo'></small><noframes id='5tAIo'>

                      • <bdo id='5tAIo'></bdo><ul id='5tAIo'></ul>