PHP function timeout handling method_php tips

WBOY
Release: 2016-05-16 19:58:38
Original
1183 people have browsed it

The example in this article describes how to handle PHP function timeout. Share it with everyone for your reference, the details are as follows:

register_shutdown_function

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

This function can be registered repeatedly and will be called sequentially. This function will be called when a fatal error or exit occurs

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);

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction to PHP Basic Syntax Tutorial", "Summary of PHP Error and Exception Handling Methods" and " Summary of common PHP functions and techniques

I hope this article will be helpful to everyone in PHP programming.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template