dongmou9260 2018-06-18 14:49
浏览 58

PHP Cpanel Cron与Argv

I have a cron job that runs daily (for over a year) and suddenly does not work.

I have a cron job that looks like:

/usr/bin/php -q /home/tcanfarotta22/public_html/test_arg.php low_customer=2 high_customer=200

And then a PHP script that gets the variables like:

parse_str($argv[1], $params);
parse_str($argv[2], $params2);

$low_customer = $params['low_customer'];
$high_customer = $params2['high_customer'];

Now I am getting the following errors:

[18-Jun-2018 10:38:01 America/New_York] PHP Notice: Undefined variable: argv in /home/tcanfarotta22/public_html/test_arg.php on line 5 [18-Jun-2018 10:38:01 America/New_York] PHP Notice: Undefined variable: argv in /home/tcanfarotta22/public_html/test_arg.php on line 6 [18-Jun-2018 10:38:01 America/New_York] PHP Notice: Undefined index: low_customer in /home/tcanfarotta22/public_html/test_arg.php on line 8 [18-Jun-2018 10:38:01 America/New_York] PHP Notice: Undefined index: high_customer in /home/tcanfarotta22/public_html/test_arg.php on line 9

Nothing has changed so I ma not sure what to do. Does anyone know?

  • 写回答

1条回答 默认 最新

  • duanmianxue2687 2018-06-19 21:05
    关注

    If the enabling of register_argc_argv does not fix the issue, then maybe you are trying to access $argv within a class, in this case, you need to declare it as global before you can access it:

    global $argv;
    

    BTW, I have tested your code (executed by the terminal) and it runs like a charm.

    enter image description here

    If this does not fix the issue, maybe then you need to put more details, also we need to know how you are testing?

    评论

报告相同问题?