Why is `$_SERVER['argv']` not set during http get request but available in cli?
18:26 13 Feb 2012

I'm trying to write a script to fetch data. The script should be invoked either by

  • a cron job running (php-cli)
  • a standard HTTP GET request

As stated on PHP website, $_SERVER['argv'] should fit my needs:

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.

However, I can't get it to work with standard HTTP GET request. $_SERVER['argv'] is not set.

What am I missing?

This is my jobs/fetch.php:

CLI output as expected:

$ php jobs/fetch.php -a -bhello`

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

GET Request response requesting jobs/fetch.php?a=&b=hello fails:

Notice: Undefined index: argv in jobs/fetch.php.
php command-line-interface query-string argv get-request