PHP Runtime Limit Function: max_execution_time ()

Any algorithm should be fast and accurate. PHP is a server language that works quickly and efficiently. One server can serve thousands of processes at the same time, but each of them can create problems for everyone else. Runtime management is important for the web property and those located next to it.

Algorithm and Time

Conditions and cycles are just two options to create problems. Serial code cannot create a real run-time delay. Even on large volumes of data, PHP can quickly cope with any task.

Time: conditions and cycles




You can confuse the script execution process by creating a stochastic system of objects. However, a modern programmer adheres to the classical traditions in programming or uses bulky site management systems. There are practically no chances to create a complex system of real objects. Server loads too.

A fatal runtime error is the result of an incorrect algorithm or a banal loop. In order to avoid server freezing, disruption of all “correct” server processes due to one “wrong” one, the php.ini file contains a time limit for executing any script - the directive: max_execution_time = 30.





Runtime Limit




Hosters usually prohibit changing the execution time of a script. But if this is possible, then using the PHP function max_execuion time (), you can set the desired value. Fundamentally, with the hoster, you can agree on the endless execution of php processes. Using the ignore_user_abort () and set_time_limit () functions, you can give the script a chance of eternal existence: it can work even if the visitor leaves the resource.

Eternal scripts and execution restriction

There are not so few tasks that require "constant care". The simplest and most accessible example is the exchange. Information from the exchange must come constantly. It doesn’t matter how many brokers are currently connected to the exchange, which of them left for lunch or fell asleep, the script should work stably for a long time, at least a full operational day.

There are other tasks that require the script to work in free mode without limiting the execution time. Whether or not to use the PHP function max_execution_time () is the will of the programmer. PHP is a fast language and in 30 seconds any algorithm fits without any problems.

Eternal scripts and exchange




When you really need to be patient - the data flow is really large or the delay in information when transmitting from the server is noticeable, you can increase the value in php.ini with the consent of the hoster. You can use the PHP function max_execution_time ().





But in any case, if there is a need to increase the execution time and there is no need to design an “eternal” algorithm, the algorithm and the conditions of the problem should be reviewed. The quality of any algorithm is transparent and clear execution. A minimum of conditions, a minimum of cycles, a simple sequence of actions is a good solution to the problem.

Conditions and cycles

How to set the required value of the PHP script execution time: max_execution_time () or ini_set () is a creative, but not essential question. It is better to contact the hoster and change the necessary directive in the php.ini file, which is exactly for this purpose.

The right conditions and cycles




Changing a directive by language means is not the most attractive idea. It is much more promising to revise the algorithm, check all current conditions and cycles. The algorithm must transparently and consistently achieve the desired result. No unnecessary branching, all loops should be controlled by the number of iterations.

Only when the cycle is maximally debugged cannot it fail. Only when the number of conditions is kept to a minimum can we not attach any importance to changing the value of the runtime directive. The task will be solved in a timely manner.




All Articles