如何在几秒钟后退出php代码?

时间:2021-02-26 03:53:42

I want to exit my php code after 10 seconds. Is there any possible way to do that? I have already found this code but it's not working.

我想在10秒后退出php代码。有可能的办法吗?我已经找到了这个代码,但是它不能工作。

set_time_limit(10);  *//this line is blocked from the server*
ini_set('max_execution_time', 10);

1 个解决方案

#1


3  

Did you put set_time_limit at the begining of the script? if not - do it, because if you look at official documentation you will see next:

在脚本一开始就设置了set_time_limit吗?如果没有,那就去做,因为如果你看一下官方文件,你会看到下面的内容:

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

调用时,set_time_limit()从0重新启动超时计数器。换句话说,如果超时是默认的30秒,在脚本执行25秒后调用set_time_limit(20),脚本将总共运行45秒,然后超时。

Also check it's return value: "Returns TRUE on success, or FALSE on failure."

还要检查它的返回值:“成功时返回TRUE,失败时返回FALSE。”

PS: "The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real."

PS:“set_time_limit()函数和配置指令max_execution_time只影响脚本本身的执行时间。在确定脚本运行的最大时间时,不包括在执行脚本之外的任何活动上花费的时间,例如使用system()的系统调用、流操作、数据库查询等。这在实测时间是真实存在的Windows上是不正确的。

Does it help?

它有帮助吗?

All written above you can find in http://php.net/manual/en/function.set-time-limit.php

以上所有内容都可以在http://php.net/manual/en/function.set-time-limit.php中找到

#1


3  

Did you put set_time_limit at the begining of the script? if not - do it, because if you look at official documentation you will see next:

在脚本一开始就设置了set_time_limit吗?如果没有,那就去做,因为如果你看一下官方文件,你会看到下面的内容:

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

调用时,set_time_limit()从0重新启动超时计数器。换句话说,如果超时是默认的30秒,在脚本执行25秒后调用set_time_limit(20),脚本将总共运行45秒,然后超时。

Also check it's return value: "Returns TRUE on success, or FALSE on failure."

还要检查它的返回值:“成功时返回TRUE,失败时返回FALSE。”

PS: "The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real."

PS:“set_time_limit()函数和配置指令max_execution_time只影响脚本本身的执行时间。在确定脚本运行的最大时间时,不包括在执行脚本之外的任何活动上花费的时间,例如使用system()的系统调用、流操作、数据库查询等。这在实测时间是真实存在的Windows上是不正确的。

Does it help?

它有帮助吗?

All written above you can find in http://php.net/manual/en/function.set-time-limit.php

以上所有内容都可以在http://php.net/manual/en/function.set-time-limit.php中找到