2.11.7. Passing parameters to the running script

When starting a script with predefined values of variables, it is more convenient to pass them in the task launch line, so as not to make changes to the script itself every time.

To do this, you should write the cron task in the following form:

путь_к_interpreter -f путь_к_script variables_across_space


/usr/local/bin/php -f /home/name_hosting/путь_к_script/script.php 15 test 23

In the script itself, at the beginning (from the second line), you need to add the assignment of values to the desired variables through a variable $argv: $argv[1] — the first parameter, $argv[2] — the second, etc.



In this example, after these lines, the variable $a inside the script will equal 15, variable $some_text will be equal testand the variable $age23.

If you need to change the settings of a specific host (site), then you can use the following option:

путь_к_interpreter -c path_к_ini_file_host -f путь_к_script variables_across_space


/usr/local/bin/php -c /home/name_hosting/.system/php/www.name_host.ini -f /home/name_hosting/путь_к_script/script.php 15 test 23

The same example for host example.su (located in the hosting account example) using version 7.2 of the PHP interpreter

/usr/local/php72/bin/php -c /home/example/.system/php/www.example.su.ini -f /home/example/путь_к_script/script.php 15 test 23