What are the differences between using PHP CLI and PHP CGI in terms of handling command line arguments like $argv?
When using PHP CLI, command line arguments can be accessed using the predefined $argv array. However, when using PHP CGI, command line arguments are not automatically passed to the script in the same way. To handle command line arguments in PHP CGI, you can use the $_SERVER['argv'] and $_SERVER['argc'] superglobals instead.
// Check if running under PHP CLI or CGI
if (php_sapi_name() == 'cli') {
$args = $argv;
} else {
$args = $_SERVER['argv'];
}
// Access command line arguments
foreach ($args as $arg) {
echo $arg . "\n";
}