php - 我可以为代码块设置时间限制吗?

标签 php php-5.3

是否可以启动一个代码块(也许只是调用一个函数),如果它没有在特定时间内执行则跳过它。

//give this function 10 seconds to execute
$value = mega_function();// could take anything from 1-1000 seconds
//if 10 seconds have passed and the value is still not set, abort it and set $value = false;

最佳答案

没有。你必须要么

  • 使用 curl 或 file_get_contents() 调用外部文件中的函数 - 您可以在那里设置超时

  • 如有必要,请跟踪 mega_function()return() 中的时间。

mega_function() 有什么作用?

关于php - 我可以为代码块设置时间限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5960497/

相关文章:

PHP:使用带有 mysqli_connect 的持久连接会导致管道损坏错误

php - Laravel Eloquent 排序查询

php - Laravel 请求转换

php - 更新数据库中表行的快捷方式?

php - 是否可以在 PHP 中编写一系列重复引用单个对象的语句?

php - 如何验证上传的文件是视频?

php - .user.ini 文件是否适用于子目录?

php - 设置一个新的 Cron 来运行 PHP 文件,但似乎没有任何反应

php - 如何在 codeigniter 中编写这个复杂的查询?

php - 更新数据库前检查变量类型 | PHP