Command line execution of the $argv and $argc configuration methods in the php script
- 2021-08-31 07:24:12
- OfStack
In actual work, it is possible to encounter the need to execute php scripts on the nginx command line. Of course, you can configure an conf to use external network access.
Use on the nginx command line
php index.php
You can execute the index. php script, but how do you pass the parameters? That will require $argv and $aegc. Use it directly in the script without opening any settings, similar to $_ POST and $_ GET in the http pass-through.
Insert the following dishes in index. php
<?php
echo $argv[0]; echo "\n";
var_dump($argv[1]); echo "\n";
var_dump(intval($argv[2])); echo "\n";
echo $argv[3]; echo "\n";
echo $argc;
Then use it on the nginx command line
php index.php 1 10 100
Display
index.php //$argv[0] Display results What is shown here after testing is the relative path of this script relative to the execution location ( That's where you entered it php index.php, What is shown here is index.php Relative to the location of your current directory )
string(1) "1" //$argv[1] Display number 1 Parameters are converted to strings
int(10) //$argv[2] Display number 2 Parameters
100 //$argv[3] Display number 2 Parameters
4 //$argv Number of parameters Relative path + The parameters you passed
Check this variable 1 times for easy memory
$avgv 为 argument vector, $avgc 为 argument count
Details:
http://php.net/manual/zh/reserved.variables.argv.php#93532
Summarize