大部分PHP代码执行时间都不会很久。但是有些时候,比如等待图片上传,可能执行时间过长导致超时。
php.ini 中缺省的最长执行时间是 30 秒,这是由 php.ini 中的 max_execution_time 变量指定,倘若你有一个需要颇多时间才能完成的工作,例如要发送很多电子邮件给大量收件者,或者要进行繁重的数据分析工作,服务器会在 30 秒后强行中止正在执行的程序,如何解决这个问题呢。
最简单当然是修改 php.ini 中 max_execution_time 的数值,不过不是所有人都有权修改 php.ini,例如使用网页寄存的开发人员,服务器上的 php.ini 由很多网站共同使用,所以不能随意修改。
另一个办法是在 PHP 程序中加入 ini_set('max_execution_time', '0'),数值 0 表示没有执行时间的限制,你的程序需要跑多久便跑多久。若果你的程序仍在测试阶段,推荐你把时限设置一个实数,以免程序的错误把服务器当掉。
<?php //max_execution_time=100; ini_set("max_execution_time", 1); //用此function才能真正在运行时设置 for($i=1; $i< 100000; $i++) { echo "No. {$i}\n"; echo '<br />'; flush(); } ?>
同时可以使用ini_get把原来设置的max_execution_time保存下来,在进行完操作时回复原来的设定值。
在这里简单记录下~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor