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

    <small id='2Nm5r'></small><noframes id='2Nm5r'>

        <legend id='2Nm5r'><style id='2Nm5r'><dir id='2Nm5r'><q id='2Nm5r'></q></dir></style></legend>
          <bdo id='2Nm5r'></bdo><ul id='2Nm5r'></ul>

        将变量传递给从命令行运行的 PHP 脚本

        时间:2023-10-04

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

        • <small id='Nhwxy'></small><noframes id='Nhwxy'>

          <tfoot id='Nhwxy'></tfoot>
            <legend id='Nhwxy'><style id='Nhwxy'><dir id='Nhwxy'><q id='Nhwxy'></q></dir></style></legend>
              <bdo id='Nhwxy'></bdo><ul id='Nhwxy'></ul>
                <tbody id='Nhwxy'></tbody>

                1. 本文介绍了将变量传递给从命令行运行的 PHP 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个需要从命令行运行的 PHP 文件(通过 crontab).我需要将 type=daily 传递给文件,但我不知道如何.我试过了:

                  I have a PHP file that is needed to be run from the command line (via crontab). I need to pass type=daily to the file, but I don't know how. I tried:

                  php myfile.php?type=daily
                  

                  但是返回了这个错误:

                  无法打开输入文件:myfile.php?type=daily

                  Could not open input file: myfile.php?type=daily

                  我能做什么?

                  推荐答案

                  ?type=daily 参数(以 $_GET 数组结尾)仅对网页访问页面.

                  The ?type=daily argument (ending up in the $_GET array) is only valid for web-accessed pages.

                  您需要像 php myfile.php daily 一样调用它,并从 $argv 数组(这将是 $argv[1],因为 $argv[0] 将是 myfile.php).

                  You'll need to call it like php myfile.php daily and retrieve that argument from the $argv array (which would be $argv[1], since $argv[0] would be myfile.php).

                  如果页面也用作网页,您可以考虑两种选择.使用 shell 脚本和 Wget 访问它,然后从 cron:

                  If the page is used as a webpage as well, there are two options you could consider. Either accessing it with a shell script and Wget, and call that from cron:

                  #!/bin/sh
                  wget http://location.to/myfile.php?type=daily
                  

                  或者检查PHP文件是否从命令行调用:

                  Or check in the PHP file whether it's called from the command line or not:

                  if (defined('STDIN')) {
                    $type = $argv[1];
                  } else {
                    $type = $_GET['type'];
                  }
                  

                  (注意:您可能需要/想要检查 $argv 是否确实包含足够的变量等)

                  (Note: You'll probably need/want to check if $argv actually contains enough variables and such)

                  这篇关于将变量传递给从命令行运行的 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:合并两个大小相等的平面索引数组,以便将值以 下一篇:如何在 Windows 上使用命令行访问 PHP?

                  相关文章

                  最新文章

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

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

                  <tfoot id='u6siz'></tfoot>

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