For those who are awake!
Discount -15%
We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

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

Example:

/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.

Example:

$a=$argv[1];
$some_text=$argv[2];
$age=$argv[3];

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), you can use the following option:

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

Example:

/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 the host example.su (located in the example hosting account) 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
Content