Adjust max_execution_time in PHP and Centos 7 Server

Explain about max_execution_time in PHP and Centos 7 Servers. When we deal with data processing using the script code with the PHP interpreter then surely someday will be faced with the problem of execution time.

Time of execution of the process data in the beginning is always low and will always be the case because at the time the data we use is still very little. Within 1 to 10 seconds was more than enough to process all the data. However, what happens when the data stored on the database has reached tens of thousands and at the same time we apply data processing in the form of update, delete, create and edit? Of course the question of the execution time is starting to appear here.

max_execution_time in PHP and Centos 7 Server
Adjust max_execution_time in PHP and Centos 7 Server

By default, PHP provides a maximum execution time that is 120 seconds. This is related to the server's security problems and the availability of the server to always ready at any moment at any time accessible.

In contrast to a server that is specialized for the backend, the processing time can be adjust more than that without reducing the security and existence of the server itself. Normally, the administrator will add processing time up to a maximum of 2 days.

Let's assume, if in 1 second the server is able to process the data as much as 10 field then within 2 days or 10368000 seconds of each server will be capable of processing as much as 1036800000 field data.

I think that much time was more than enough.

But what if the data is in the process of not only text but also there are pictures and videos as well as other digital files? Will certainly take much longer even though the data is in the process of the mungkina in 2 days only about 2 thousands of data.

I explained here there are 2 alternatives which can be used to add to the processing time of the data.

1. Via .htaccess

To add processing time via .htaccess is easy, you just add the following code :

< IfModule mod_php7. c >
php_value max_execution_time 10368000
</IfModule>

Mod_php7. c code which you can customize with PHP version than you are currently using. For example for PHP 5, Change mod_php7. c be mod_php5. c.

To be able to find out what version of PHP that currently we are using, the type the following commands on your linux server CLI.

httpd -V

The result will look like the following:

[user @ server ~] # httpd -V
Server version: 2.4.6/Apache (CentOS)
Server built: Oct 19 2017 20:39:16
Server's Module Magic Number: 20120211:24
Server loaded: APR, APR-UTIL 1.4.8 1.5.2
1.4.8 compiled using: APR, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: event
threaded: yes (fixed thread count)
United: yes (variable process count

Well, it's been caught not version PHPnya? Please customize and enter the above code in the htacces file in the root folder of your domain and server automatically processing time has now been changed accordingly we enter.

2. Via inline PHP Script

To set up and adjust processing time via inline PHP script, insert this code before the code process data:
ini_set (' max_execution_time ', 10368000);

The second way is the same nature with the first way, will produce the maximum processing time up to 2 days.

What if processing time like to made unlimited?

To make the processing time so that without limits, change "10368000" value with "0" /zero.

php_value max_execution_time 0

or

ini_set (' max_execution_time ', 0);


This way I think safer for the server because we do not need to make changes to the actual server and code will only change one value for a given domain that we are setting. It would be very risky if we change it via PHP.ini on a production server. Not all domain or script data prosessing requires extra time more than the default PHP.

That's all. All it takes to add processing time to indefinitely. Hopefully helpful. If you have another better way, please leave so many people commented on it helpful with your advice.

0 Response to "Adjust max_execution_time in PHP and Centos 7 Server"

Posting Komentar