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

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

      <tfoot id='afBry'></tfoot>

    2. $_SERVER['argv'] 带有 HTTP GET 和 CLI 问题

      $_SERVER[#39;argv#39;] with HTTP GET and CLI issue($_SERVER[argv] 带有 HTTP GET 和 CLI 问题)

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

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

          <tfoot id='MOnWX'></tfoot>

          1. <legend id='MOnWX'><style id='MOnWX'><dir id='MOnWX'><q id='MOnWX'></q></dir></style></legend>
            • <bdo id='MOnWX'></bdo><ul id='MOnWX'></ul>
                <tbody id='MOnWX'></tbody>
                本文介绍了$_SERVER['argv'] 带有 HTTP GET 和 CLI 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试写一个脚本来获取一些在线数据;脚本应由 cron 作业或 php cli 和标准的 GET HTTP 请求 调用.正如 PHP 网站上所述 $_SERVER['argv'] 应该符合我的需求:

                I'm trying to write down a script to fetch some online data; script should be invoked either by a cron job or php cli and with standard GET HTTP request. As stated on PHP website $_SERVER['argv'] should fit my needs:

                传递给脚本的参数数组.当脚本在命令行,这提供了对命令行的 C 风格访问参数.当通过 GET 方法调用时,这将包含查询字符串.

                Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.

                但是我无法让它与标准的 HTTP GET 请求一起工作.$_SERVER['argv'] 未设置.我错过了什么?

                However i can't get it to work with standard HTTP GET request. $_SERVER['argv'] is not setted. What i'm missing?

                <?php
                    // jobs/fetch.php
                    var_dump($_SERVER['argv']);
                ?>
                

                CLI 输出 php jobs/fetch.php -a -bhello:

                array(3) {
                  [0]=>
                  string(14) "jobs/fetch.php"
                  [1]=>
                  string(2) "-a"
                  [2]=>
                  string(7) "-bhello"
                }
                

                GET 输出 jobs/fetch.php?a=&b=hello:

                注意:未定义索引:jobs/fetch.php 中的 argv.

                Notice: Undefined index: argv in jobs/fetch.php.

                推荐答案

                手册没有很好地说明这一点,但是,如果你想要 $_SERVER['argc'], $_SERVER['argv'], $argc, $argv 要在您未在 CLI 模式下运行时注册,然后是 php.ini 值 register_argc_argv 需要在 php.ini 中启用(默认关闭 [出于性能原因]).

                The manual didn't state this very well, but, if you want $_SERVER['argc'], $_SERVER['argv'], $argc, $argv to be registered when you are not running in CLI mode, then the php.ini value register_argc_argv needs to be enabled in php.ini (off by default [for performance reasons]).

                您可以执行以下操作来获取 argv,或根据脚本的运行方式查询字符串 args:

                You could do the following to get argv, or query string args depending on how the script is running:

                if (php_sapi_name() == 'cli') {
                    $args = $_SERVER['argv'];
                } else {
                    parse_str($_SERVER['QUERY_STRING'], $args);
                }
                

                以下是来自 php.ini 的一些细节:

                Here are some details from php.ini:

                ; This directive determines whether PHP registers $argv & $argc each time it
                ; runs. $argv contains an array of all the arguments passed to PHP when a script
                ; is invoked. $argc contains an integer representing the number of arguments
                ; that were passed when the script was invoked. These arrays are extremely
                ; useful when running scripts from the command line. When this directive is
                ; enabled, registering these variables consumes CPU cycles and memory each time
                ; a script is executed. For performance reasons, this feature should be disabled
                ; on production servers.
                ; Note: This directive is hardcoded to On for the CLI SAPI
                ; Default Value: On
                ; Development Value: Off
                ; Production Value: Off
                ; http://php.net/register-argc-argv
                

                另见http://www.php.net/manual/en/reserved.variables.argv.php 和 parse_str().

                这篇关于$_SERVER['argv'] 带有 HTTP GET 和 CLI 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

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

                      <tbody id='LtJpa'></tbody>

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

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

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