Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How to get internal arguments?

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 it

I'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.

like image 586
Levi Morrison Avatar asked Mar 21 '13 21:03

Levi Morrison


People also ask

How do you get the number of arguments passed to a PHP function?

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.

What is $_ GET?

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>

What is the function Func_num_args () used for?

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.

What does ?: Mean in PHP?

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.


1 Answers

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
like image 154
bizzehdee Avatar answered Oct 07 '22 01:10

bizzehdee