$_SERVER['argv'] with HTTP GET and CLI issue

前端 未结 2 1503
时光说笑
时光说笑 2021-01-03 00:32

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 re

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 01:10

    You will have to use $_GET or $_SERVER['argv'] depending on how your script is called. Neither one is used for both.

    For example:

    if(!empty($_SERVER['argv'][0]) {
      $a = $_SERVER['argv'][1];
      $b = $_SERVER['argv'][2];
    } else {
      $a = $_GET['a'];
      $b = $_GET['b'];
    }
    

提交回复
热议问题