Main PHP Timeout Directives
To get the current timeout value in PHP, use the built-in function ini_get() with the name of the required directive from the configuration php.ini. The choice of parameter depends on which specific timeout you need. [1]
Main PHP Timeout Directives
-
Maximum script execution time. To find out the time limit for the script itself, query the
max_execution_timeparameter. The value is returned in seconds (by default it is usually30, and0means there is no limit). -
Time for parsing input data. The
max_input_timeparameter shows how many seconds the script is given to read data fromPOST,GETand to upload files. -
Default socket timeout. The
default_socket_timeoutdirective returns the wait timeout when working with network streams (for example, when usingfile_get_contents()). -
Session lifetime. To get the session inactivity timeout, use the
session.gc_maxlifetimedirective. [1, 2, 3]
Code Example
php
<?php
// Максимальное время выполнения скрипта (в секундах)
$executionTimeout = (int) ini_get('max_execution_time');
// Максимальное время обработки входных данных (POST/GET)
$inputTimeout = (int) ini_get('max_input_time');
// Таймаут для сетевых потоков и сокетов
$socketTimeout = (int) ini_get('default_socket_timeout');
echo "Таймаут скрипта: {$executionTimeout} сек.\n";
echo "Таймаут ввода: {$inputTimeout} сек.\n";
echo "Таймаут сокетов: {$socketTimeout} сек.\n";
Use the code with caution.
Important Limitation (Web Server)
The ini_get() function only returns the settings of PHP itself (you can learn more in the documentation PHP.net). It is not possible to retrieve the web server timeouts (for example, fastcgi_read_timeout in Nginx or Timeout in Apache) directly from a PHP script using standard tools, because these parameters are set at the level of the web server configuration itself and are not passed to the PHP environment.