$ GLOBALS ["argv"] and $ argv empty, $ _SERVER ["argv"] are just fine

I am struggling with a (possibly) simple problem with the PHP CLI running on Hostgator hosting. Simple code:

<?php var_dump($argv); var_dump($GLOBALS["argv"]); var_dump($_SERVER["argv"]); var_dump(ini_get("register_argv_argv")); ?> 

When launched on my local computer, as well as in several other php instances:

 php test.php arg1 

It is displayed correctly, as predicted:

 array ( 0 => 'test.php', 1 => 'arg1' ) array ( 0 => 'test.php', 1 => 'arg1' ) array ( 0 => 'test.php', 1 => 'arg1' ) 1 

But run cron on the Hostgator hosting, which it issues:

 array ( ) NULL array ( 0 => 'test.php', 1 => 'arg1' ) 1 

The code I'm struggling with is deprecated, and it relies heavily on $ GLOBALS ["argv"] to parse command-line options. I don’t have the means to change the entire codebase to use $ _SERVER ["argv"] instead.

What could be the reason that all my PHP instances fill all arrays with command line parameters, and hosted php hostgator doesn't fill $ GLOBALS ["argv"] at all?

I made a workaround to solve this problem, but I hate it when I don’t know why something is happening :)

Thanks for any ideas!

+4
source share
1 answer

I had the same problem without $_SERVER['argv'];

Try php-cli instead of php :

 $job = "* * * * * php-cli /home/user/file.php surf"; 

it worked for me!

+6
source

Source: https://habr.com/ru/post/1438892/


All Articles