How to Create a Phpinfo File and Check PHP Information. Deliver files efficiently using PHP Attentive info php

(PHP 3, PHP 4, PHP 5)

phpinfo - displays a lot of information about PHP.

Description

int phpinfo()

Displays a large amount of information about the current PHP status. This includes information about PHP compilation options and extensions, PHP version, server and environment information (if compiled as a module), PHP environment, OS version, paths, master and local configuration option variables, HTTP and PHP License headers. Since each system is configured differently, phpinfo() is usually used to check configuration settings and the availability of predefined variables on a given system. Phpinfo() is also an important debugging utility, as it contains all the EGPCS data (Environment, GET, POST, Cookie, Server ). The output can be specialized by passing one or more of the following constant bit values ​​summed in the optional what parameter. You can also combine corresponding constant or bit values ​​using the operation.

Table 1. phpinfo() options
Name (constant) Value Description INFO_GENERAL1 Configuration string, php.ini location, build date, Web server, system, etc.INFO_CREDITS2PHP Credits 4.See. also phpcredits() .INFO_CONFIGURATION4Current Local and Master values ​​of php directives.See. also ini_get() .INFO_MODULES8 Loaded modules and their corresponding settings.INFO_ENVIRONMENT16Environment Variable information, also available in $_ENV .INFO_VARIABLES32Shows all predefined variables from EGPCS (Environment, GET, POST, Cookie, Server).INFO_LICENSE64PHP License information.See. also license faq .INFO_ALL-1All of the above. This is the default value.

Note: parts of the information displayed are disabled when the expose_php configuration setting is set to off . This includes PHP and Zend logos and credits. See. Also

Any software, which you want to run on your web server has certain requirements that it must meet. For example, WordPress requires PHP version 5.2.4 or higher. Depending on the server, you can change some PHP settings, others, on the contrary, are prohibited from changing, however, information about all of them can be found in the phpinfo file. In this tutorial, you will learn how to create a phpinfo file and find out the values ​​and status of PHP modules. This can also be useful for getting information about your hosting account such as max_execution_time, memory_limit, post_max_size and others.

Before you start this guide, you will need the following:

  • Access to your hosting control panel or FTP account

Option 1 - Checking PHP Information Through Your Hosting Control Panel

At Hostinger, your account's PHP information can be found in the Advanced → PHP Information. This is a very convenient feature, since you will not need to create additional files on your hosting.

After this, you will be taken to a page with all the necessary information about your PHP version, modules and values. To search for a specific module or function, use the search by pressing the keyboard shortcut CTRL+F.

Congratulations! You have learned how to access your php information through the Hostinger control panel.

Option 2 - Checking PHP Information by Creating a phpinfo.php File

Don't worry if your hosting platform doesn't support the feature shown in Option 1. The same result can be achieved by creating a special file inside your hosting account. The file will also show all the information about your PHP and will be accessible through the browser.

Step 2.1 - Create a phpinfo file

There are several ways to create a phpinfo file. In this tutorial we will use . However, the same result can be achieved by creating a file on your local computer and further uploading the file to the server via .

Login to your hosting control panel and open File manager . Click the button New file to create a new file.

In the first field, indicate the path where it will be created new file. Next, in the field New file name enter phpinfo.php. In most cases you can leave the path unchanged /public_html. In this case, the file will be created in the root directory of your site.

Step 2.2 - Editing the file

At this stage you already have an empty file phpinfo.php in the catalog public_html. Copy the following code to a file and click the icon Save in the left corner of the screen.

That's it, you have successfully created PHP file which will display all your PHP options. As mentioned earlier, the same result can be achieved using:

  1. Use any text editor and create a file phpinfo.php on your computer.
  2. Add the following code to the file:
  1. Upload the file using FTP to your directory public_html.

Step 2.3 - Checking PHP Information via Browser

If everything was done correctly, you can now access the created file by adding to the end of your domain name /phpinfo.php. Eg, http://yourdomain.ru/phpinfo.php

You should see a similar result when opening this page through a browser:

On this page you will be able to see all your PHP settings.

Conclusion

By finishing this tutorial, you have learned how to create a phpinfo file and check your information. PHP settings. This information is useful if you want to know your hosting settings or run software that requires certain PHP modules.

If you needed to send files not directly by the web server, but from using PHP(for example, to collect download statistics), please under cat.

1. Use readfile()

The good thing about this method is that it works out of the box. You just need to write your own file sending function (slightly modified example from the official documentation):

Function file_force_download($file) ( if (file_exists($file)) ( // reset the buffer PHP output to avoid overflowing the memory allocated for the script // if this is not done, the file will be read into memory completely! if (ob_get_level()) ( ob_end_clean(); ) // force the browser to show the window for saving the file header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream"); ​​header("Content-Disposition: attachment; filename=" . basename($file)); header("Content-Transfer-Encoding: binary") ; header("Expires: 0"); header("Cache-Control: must-revalidate"); header("Pragma: public"); header("Content-Length: " . filesize($file)); // read the file and send it to the user readfile($file); exit; ) )
Even large files can be sent this way, since PHP will read the file and immediately give it to the user in parts. The documentation clearly states that readfile() should not create memory problems.

Peculiarities:

  • The file is read into the internal buffer of the readfile() function, the size of which is 8kB (thanks 2fast4rabbit)

2. Read and send the file manually

The method uses the same Drupal when sending files from a private file system(files are not available directly via links):

Function file_force_download($file) ( if (file_exists($file)) ( // reset the PHP output buffer to avoid overflowing the memory allocated for the script // if this is not done, the file will be read into memory completely! if (ob_get_level()) ( ob_end_clean(); ) // force the browser to show the window for saving the file header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream"); ​​header("Content-Disposition: attachment; filename =" . basename($file)); header("Content-Transfer-Encoding: binary"); header("Expires: 0"); header("Cache-Control: must-revalidate"); header("Pragma: public"); header("Content-Length: " . filesize($file)); // read the file and send it to the user if ($fd = fopen($file, "rb")) ( while (!feof($ fd)) ( print fread($fd, 1024); ) fclose($fd); ) exit; ) )
Peculiarities:

  • The script waits until the entire file is read and given to the user.
  • Allows you to save server memory

3. Use the web server module

3a. Apache
The XSendFile module allows you to send a file to Apache itself using a special header. There are versions for Unix and Windows, under versions 2.0.*, 2.2.* and 2.4.*

In the host settings you need to enable header interception using the directive:
XSendFile On
You can also specify a white list of directories in which files can be processed. Important: if you have a server based Windows path must include an uppercase drive letter.

Description of possible options on the developer's website: https://tn123.org/mod_xsendfile/

Example of sending a file:

Function file_force_download($file) ( if (file_exists($file)) ( header("X-SendFile: " . realpath($file)); header("Content-Type: application/octet-stream"); ​​header(" Content-Disposition: attachment; filename=" . basename($file)); exit; ) )

3b. Nginx
Nginx can send files out of the box via a special header.

For correct operation, you need to deny access to the folder directly through the configuration file:
location /protected/ ( internal; root /some/path; )
Example of sending a file (the file must be in the /some/path/protected directory):

Function file_force_download($file) ( if (file_exists($file)) ( header("X-Accel-Redirect: " . $file); header("Content-Type: application/octet-stream"); ​​header("Content -Disposition: attachment; filename=" . basename($file)); exit; ) )
More information on the official documentation page

Peculiarities:

  • The script ends immediately after all instructions are completed
  • Physically, the file is sent by the web server module itself, and not by PHP
  • Minimal consumption of memory and server resources
  • Maximum performance

Update: Habrowser ilyaplot gives good advice that it is better to send not application/octet-stream , but the real mime type of the file. For example, this will allow the browser to substitute necessary programs into the file save dialog.




Top