PHPLover
PHPLover

Reputation: 12957

Who reads the 'php.ini' file and how many php.ini files can possibly be exist there? What's the role of every such 'php.ini' file?

I'm using PHP 7.2.10 on my laptop that runs on Windows 10 Home Single Language 64-bit operating system.

I've installed Apache/2.4.34 (Win32) and PHP 7.2.10 using the latest version of XAMPP.

Today, I come across the following statement from PHP Manual :

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

Above text has created following doubts in my mind :

  1. What does exactly mean by first sentence? It's only saying that

The configuration file (php.ini) is read when PHP starts up.

But it's not saying who does read it? Is it the PHP parser or the Apache web server? Or something else? Please explain to me.

  1. In case of CGI and CLI versions, why the php.ini file is read again and again and who reads it?

  2. In case of CGI and CLI versions, the process of reading the php.ini file happens on every invocation? What does mean by this sub-clause every invocation?

  3. How many php.ini files can possibly be exist there? If such more than one files exist then what's the role of every such php.ini file?

P.S. : All the above questions have been asked to me in a technical interview.

P.S. : I know that php.ini is the main configuration file with all the configuration setting on the local machine.

Upvotes: 0

Views: 427

Answers (1)

Jay Blanchard
Jay Blanchard

Reputation: 34426

  1. The PHP compiler/parser.
  2. Because PHP does not persist for command line invocations, so it is read at run-time.
  3. Every time you call a PHP script, either CGI or CLI.
  4. More than one, typically 2. One for the web server and one for CLI/CGI.

Upvotes: 4

Related Questions