SoFunction
Updated on 2025-03-09

Analyze the application of argc argv in php

argc, argv is useful when compiling programs with the command line
We will find such parameters in the timing task script, $obj->run($argv[1]);
*/30 * * * * /usr/local/bin/php /htdocs//uaqm/commands/ 1 >/dev/null 2>&1
Just like the timing task above, if we add the parameter $argv[1] when calling it, it means that the first string after executing the program name in the DOS command line in the script
That is, the corresponding red 1 in the above script, if we deploy the timing tasks listed below
*/30 * * * * /usr/local/bin/php /htdocs//uaqm/commands/ 1 >/dev/null 2>&1
*/30 * * * * /usr/local/bin/php /htdocs//uaqm/commands/ 2 >/dev/null 2>&1
*/30 * * * * /usr/local/bin/php /htdocs//uaqm/commands/ 3 >/dev/null 2>&1
So we think this task is divided into three processes, which means that the pressure becomes one-third of the original, so it is easy to understand.

The official explanation of these two keywords is released below.
argc: integer, used to count the number of command line parameters you give to the main function when you run the program
* argv: String array, used to store pointer arrays to your string parameters, each element points to a parameter
argv[0] points to the full path name of the program running
argv[1] points to the first string after executing the program name in the DOS command line
argv[2] points to the second string after executing the program name
argv[argc] is NULL