Content · Programming · PHP

PHP phpinfo() Function: Usage and Examples

Learn PHP phpinfo() through clear code examples, practical usage, important limitations and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

phpinfo() outputs detailed PHP runtime configuration and extension information. This guide explains the function with focused examples and the decisions that matter in real applications.

What Is phpinfo() in PHP?

Outputs detailed PHP runtime configuration and extension information.

A typical call looks like this:

<?php

phpinfo([$flags]);

The input arguments shown in the call identify the relevant connection, resource, value, path or configuration for the operation. Pay attention to argument order and to the return value demonstrated below.

Example 1: Basic Usage

This first example uses phpinfo() directly to demonstrate its basic purpose.

<?php

phpinfo(INFO_GENERAL);

The returned value illustrates outputs detailed PHP runtime configuration and extension information. Never expose full phpinfo output publicly in production.

Example 2: A Different Input or Option

The next example changes the input or option, showing another supported use of phpinfo().

<?php

phpinfo(INFO_MODULES);

The returned value illustrates outputs detailed PHP runtime configuration and extension information. Never expose full phpinfo output publicly in production.

Practical Example: Applying the Function

In application code, phpinfo() belongs in a controlled workflow with input validation, a checked result and cleanup where needed.

<?php

ob_start(); phpinfo(INFO_CONFIGURATION); $information = ob_get_clean(); echo "Configuration bytes: " . strlen($information);

The returned value illustrates outputs detailed PHP runtime configuration and extension information. Never expose full phpinfo output publicly in production.

Important Behavior and Edge Cases

  • Main behavior: Outputs detailed PHP runtime configuration and extension information.
  • Important limitation: Never expose full phpinfo output publicly in production.
  • Requirements: Check the runtime, file permissions and operating system when results depend on the environment.

Comparison With Related Functions

Function or ApproachWhen to Use It
phpinfo()Outputs detailed PHP runtime configuration and extension information.
ini_getReads one specific PHP configuration option rather than printing the full phpinfo report.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the specific limits or preconditions of phpinfo().Never expose full phpinfo output publicly in production.
Assuming every environment produces the same result.Check the runtime, file permissions and operating system when results depend on the environment.

Key Takeaways

  • Outputs detailed PHP runtime configuration and extension information.
  • Never expose full phpinfo output publicly in production.
  • Check the runtime, file permissions and operating system when results depend on the environment.

Use phpinfo() when its behavior matches your task, and verify the relevant return value before taking further action. The output depends on the local configuration when it uses resources, files or an interactive terminal.

Share this resourceSend this page to someone who may find it useful.