Heim  >  Artikel  >  Backend-Entwicklung  >  PHP执行时间函数 ini_set与max_execution_time

PHP执行时间函数 ini_set与max_execution_time

WBOY
WBOYOriginal
2016-07-25 08:54:201699Durchsuche
介绍下php中执行时间函数ini_set与max_execution_time的用法,有需要的朋友参考下。

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')或set_time_limit('0'),数值 0 表示没有执行时间的限制,你的程序需要跑多久便跑多久。若果你的程序仍在测试阶段,推荐你把时限设置一个实数,以免程序的错误把服务器当掉。



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn