1

I want to passing the parameters on following function:

system("/usr/bin/nohup /usr/bin/php -q /var/www/vhosts/example.com/httpdocs/foldername/filename.php > /dev/null 2> /dev/null &");

I have tried following things but no luck.

  1. system("/usr/bin/nohup /usr/bin/php -q /var/www/vhosts/example.com/httpdocs/foldername/filename.php?abc=123 > /dev/null 2> /dev/null &");

  2. system("/usr/bin/nohup /usr/bin/php -q /var/www/vhosts/example.com/httpdocs/foldername/filename.php abc=123> /dev/null 2> /dev/null &");

Please explain me how i pass the parameter and how i get this parameter value on this example.php file.

Thanks

9
  • command line php does accept get strings. It is a file, not a url. You can pass arguments to the file as you would any command line script (space separated single words or quoted strings) and access those via $argv. You can read more about php's command line usage in the manual: php.net/manual/en/features.commandline.php and php.net/manual/en/reserved.variables.argv.php Feb 12, 2015 at 18:08
  • Thank you @Jonathan Kuhn, you mean system("/usr/bin/nohup /usr/bin/php -q /var/www/vhosts/example.com/httpdocs/foldername/filename.php 123 > /dev/null 2> /dev/null &"); right ?
    – saqib khan
    Feb 12, 2015 at 18:12
  • You're executing on the command line. The shell has NO idea what a URL is. It's going to see the ? as a wildcard attempt, and spit out a "no match" error.
    – Marc B
    Feb 12, 2015 at 18:15
  • Yes, and 123 will be available at $argv[1] in your script (might be another index, should check with print_r($argv)). Really, you could pass a query string formatted string (I would suggest quoting it) and use parse_str to get the keys/values. $_GET = parse_str($argv[1]);. Feb 12, 2015 at 18:17
  • Thank you @Marc B, so what should i do ?
    – saqib khan
    Feb 12, 2015 at 18:18

1 Answer 1

2

Command line php doesn't accept get strings. It is a file, not a url. You can pass arguments to the file as you would any command line script (space separated single words or quoted strings) and access those via $argv. You can read more about php's command line usage in the manual:

php.net/manual/en/features.commandline.php php.net/manual/en/reserved.variables.argv.php

You could also pass a query string formatted string (I would suggest quoting it) and use parse_str to get the keys/values.

Cmd line: php scriptName.php "foo=1&bar=2"

in script:

$queryString = parse_str($argv[1]);
//and now you have:
$queryString['foo']; //equals 1
$queryString['bar']; //equals 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.