When you are processing large data with PHP on your server, you may get a 500 Internal Server Error by timing out the page. By default, PHP doesn’t allow such operations forever. Long-running operations always consume infrastructure resources; this affects the performance of your server and application. Therefore, it also manages functions such as page loading, number of simultaneous file uploads, and RAM limit.
- You may be interested in HTTP Status and Error Codes: A Comprehensive Guide
Possible causes of PHP timeout error
- Upload options in form fields
- Large database queries
- Large plugin and theme installations in frameworks (WordPress, Joomla, Drupal, etc.)
- PHP errors like infinite loops
- Large file operations
Fix of PHP timeout error
If you are a server administrator, search for the following parameters in your php.ini file and change the parameters that you’ll see in our article according to you. Which PHP version you are actively using, you need to operate on that version. Your php.ini file on your PHP server is usually located in the following paths:
If you cannot find your active php.ini file, you can continue the process by using php -i | grep php.ini command on the terminal screen.
After opening your php.ini file via terminal, find the following parameters and perform your increment process and save and exit. Here’s what those parameters do:
|max_input_time||-1||This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. The default setting is -1, which means that max_execution_time is used instead. Set to 0 to allow unlimited time.|
|upload_max_filesize||2MB||The maximum size of an uploaded file. post_max_size must be larger than this value. When an int is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.|
|post_max_size||8MB||Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. Generally speaking, memory_limit should be larger than post_max_size. When an int is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action=”edit.php?processed=1″>, and then checking if $_GET[‘processed’] is set.|
|memory_limit||128M||This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1. When an int is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.|
Changing PHP.ini settings in cPanel
If you are using cPanel, you can update your php.ini file by following the steps below. For this, go to your cPanel screen and find the “Select PHP Version” option.
Click Options to set your active PHP version.
Change the options below with the values that are most suitable for your system and save. Now, you can try the action which you got the error again.
Changing PHP.ini settings in Plesk
You can also perform the same operations on the Plesk panel. Enter the Plesk panel and go to your domain, find PHP Settings and click it.
Change your current settings according to your needs like the image below and save and exit. Now, you can try the action which you got the error again.