The maximum execution time of the php page, set_time_limit, does not work.

Source: Internet
Author: User
The maximum execution time of the php page, set_time_limit, does not work. Set_time_limit does not take effect or the solution is invalid.

 Exec ("set names 'utf8'"); // Default Code $ db-> setAttribute (PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); for ($ I = 1; $ I <5000; $ I ++) {$ SQL = "insert into 'article' ('title', 'content', 'time', 'author', 'IP ') value ('Article Title ". $ I. "',' content ". $ I. "', '000000', 'kaixin', '2017. 0.0.1 ') "; $ db-> exec ($ SQL);} $ end = microtime (TRUE); // by bbs.it-home.org $ time = $ end-$ begin; echo "executed ". $ time. "s";} catch (Exception $ e) {echo "Failed :". $ E-> getMessage () ;}?>

After executing this code, you can only insert about 1000 pieces of data, so that the page will not be executed. The execution time of the test page is about 29 seconds, that is, the maximum execution time of the page is 30 seconds.

If you know the set_time_limit function, you can set the page execution time.

The set_time_limit function is used as follows:

This function is used to set the longest execution time for this page. The internal value is 30 seconds. in php. ini, the max_execution_time variable is set. if it is set to 0, the longest time is not limited. This function is enabled only when this function is executed.

Start computing. For example, if it is set to 30 seconds, and 25 seconds have been executed before the function is executed, and the function is changed to 20 seconds, the maximum execution time of the page is 45 seconds.

Add the set_time_limit function to the program,

The page execution time is about 29 seconds, and does not work.

Someone said on the Internet that if safe_mode in php. ini is on, this function will not be executed. I checked safe_mode = off in my php. in.

Try to add set_time_limit (0); to the for loop.

 '200', 'kaixin', '192. 0.0.1 ') "; $ db-> exec ($ SQL);}...?>

And does not work. Finally, I found it online. someone said, "the set_time_limit function should be executed in linux, and windows execution may be invalid ". I have lost confidence in this function, probably because I am a windows system.

You can only modify max_execution_time = 30 in php. ini. The default value is 30 seconds. I changed it to max_execution_time = 300. restart the apache server. The result execution time is about 140 seconds, and 5000 pieces of data are finally inserted. In windows, the execution time of this page is still controlled in php. ini and max_execution_time is modified. If you use PDO to insert data into MYSQL. Insert five thousand records in about 140 seconds, and insert 10 thousand records in about 260 seconds.

The above content does not work when the set_time_limit function is executed at the maximum time on the php page. For more information, see The PHP Chinese website (www.php1.cn )!

Related articles:

Php set_time_limit () sets the page execution time

Php set_time_limit (0) function for setting the program execution time

Set_time_limit-set the maximum script execution time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.