Given the command:
/usr/bin/php -c /path/to/custom/php.ini /path/to/script.php
I'd like to get the internal options:
-c /path/to/custom/php.ini
Things I've tried that do not work:
$argv
contains ['/path/to/script.php']
getopt('c')
contains []
$_ENV
does not contain it$_SERVER
does not contain itI've also looked for a PHP_*
constant (such as PHP_BINARY
) but cannot find one for these arguments.
Is there any way to get these arguments? Note that I am not trying to obtain the loaded ini
file but any arguments that might be present here.
To get the number of arguments that were passed into your function, call func_num_args() and read its return value. To get the value of an individual parameter, use func_get_arg() and pass in the parameter number you want to retrieve to have its value returned back to you.
PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters: <html>
The func_num_args() function can return the number of arguments passed into current user-defined function. This function can generate a warning if called from outside of a user-defined function.
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
PHP has no internal way of doing this, so you are going to have to rely on certain system information and permissions.
$pid = getmypid();
$ps = `ps aux | grep $pid`;
$command = substr($ps, strpos($ps, '/usr/bin/php'));
$args = explode(' ', $command); //not pretty, should probably use preg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With