【问题标题】:Stop script from being executed more than 5 seconds [duplicate]停止脚本执行超过 5 秒 [重复]
【发布时间】:2012-11-14 16:33:29
【问题描述】:

可能重复:
Stop A Script (without fatal error) After A Certain Amount of Query/Parse Time

如果脚本在 PHP 中运行超过 5 秒,是否可以停止脚本?

我不知道我怎么知道它运行了多长时间。

【问题讨论】:

    标签: php time


    【解决方案1】:

    使用set_time_limit() 限制执行时间:

    // At the beginning of your script
    set_time_limit(5);
    

    另请阅读文档站点上的警告框:

    当 PHP 在安全模式下运行时,此功能无效。有 除了关闭安全模式或更改时间之外没有其他解决方法 php.ini 中的限制。

    【讨论】: