PHP函数超时处理方法

yipeiwu_com5年前PHP代码库

本文实例讲述了PHP函数超时处理方法。分享给大家供大家参考,具体如下:

register_shutdown_function

Registers the function named by function to be executed when script processing is complete or when exit() is called.

此函数可以重复注册,然后会依次调用 当发生致命性错误或者exit时都会调用此函数

error_reporting(0);
register_shutdown_function ( 'handleShutdown' );
function handleShutdown (){
  $error = error_get_last ();
  // 根据错误信息,判断是否是超时了
  if ( $error && strpos ( $error [ 'message' ], 'Maximum exec' )!== false )
  {
    echo 'handle time out';
  }
}
set_time_limit(2);
sleep(3);

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP基本语法入门教程》、《PHP错误与异常处理方法总结》及《php常用函数与技巧总结

希望本文所述对大家PHP程序设计有所帮助。

相关文章

两款万能的php分页类

本文为大家分享个超级好用、万能的php分页类,具体的实现代码如下 第一款php分页类 <?php /* * To change this template, choo...

PHP正则删除HTML代码中宽高样式的方法

本文实例讲述了PHP正则删除HTML代码中宽高样式的方法。分享给大家供大家参考,具体如下: 因工作需要,需要采集html,并把html内容保存到数据库中。为了避免影响使用,宽高样式需要删...

PHP实现的简单路由和类自动加载功能

本文实例讲述了PHP实现的简单路由和类自动加载功能。分享给大家供大家参考,具体如下: 项目目录如下 入口文件index.php <?php define('WEBROO...

PHP memcache扩展的三种安装方法

关于比较请看http://code.google.com/p/memcached/wiki/PHPClientComparison。推荐使用新的memcached,安装方法基本同下面,只...

Mac系统下安装PHP Xdebug

Mac系统下安装PHP Xdebug

Mac下安装PHP调试工具Xdebug 安装步骤 brew install php70 brew install php70-xdebug php -i | grep...