Backend Development 3 min read

Three Ways to Set PHP Script Maximum Execution Time

This article explains three methods—editing php.ini, using ini_set, and calling set_time_limit—to increase PHP's default 30‑second script execution limit, and provides guidance on when each method is appropriate.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Three Ways to Set PHP Script Maximum Execution Time

Three ways to set PHP script maximum execution time.

The default maximum execution time in php.ini is 30 seconds, defined by the max_execution_time variable; if a script needs to run longer, this limit must be increased.

Therefore you need to change the PHP script maximum execution time.

Method 1: Set it in php.ini:

max_execution_time = 120;

Method 2: Use PHP's ini_set function:

ini_set("max_execution_time", "120");

Method 3: Use the set_time_limit function:

set_time_limit(120);

Method 1 is mainly suitable for already deployed websites where maintainers are unfamiliar with the code structure; Methods 2 and 3 are suitable when writing code, but Method 2 is not recommended because ini_set may be disabled.

Tips: php.cn's 23rd online class starts on 2023‑04‑06, covering the PHP phase course. To enroll, contact via WeChat: phpcn01 (Month‑Month teacher).

Course delivery method:

1. Live online teaching with recordings.

2. Internal group for teacher guidance, Q&A, and homework review.

3. Downloadable electronic course source code and learning resources.

4. Dedicated supervision to prevent procrastination.

5. Student employment group for job and part‑time referrals.

Enrollment consultation:

QQ: 27220243 (Teacher Zhong).

WeChat: phpcn01 (Teacher Month).

Backend Developmentconfigurationphpmax_execution_timeini_setset_time_limit
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.