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

Moa*_*oak 5 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;
Run Code Online (Sandbox Code Playgroud)

Pek*_*ica 7

不,你必须要么

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

  • 跟踪内部时间mega_function(),return()如有必要.

怎么mega_function() 办?