set_time_limit
(PHP 3, PHP 4 )set_time_limit -- Limits the maximum execution time
Description
void set_time_limit ( int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed. 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() has no effect when PHP is running in 安全模式. There is no workaround other than turning off safe mode or changing the time limit in the php.ini. 
 注: 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. See also: max_execution_time and max_input_time ini directives. 

解决方案 »

  1.   

    谢谢,这我知道。我想30秒结果没出来,应该试sqlserver有问题,这时60秒也一样。
    主要是能否给出一个友好的提示。如
    系统忙,稍后在试。
    也就是如何捕获异常
      

  2.   

    if(!$rresult = mssql_query($query) ){
    echo "<srcipt lanugage='javascript'>alert('系统忙,稍后在试');<scrpt>";
      

  3.   


    apache 好像可以根据错误的id,自动重定向到某页,脑袋不好使,又给忘了!气忿!!!!
      

  4.   

    if(!$rresult = mssql_query($query) ){
    echo "系统忙,稍后在试";exit;
    }
      

  5.   

    哦,TNND,终于想起来了,还有一个方法restore_error_handler
    (PHP 4 >= 4.0.1)restore_error_handler --  Restores the previous error handler function 
    Description
    void restore_error_handler ( void )
    Used after changing the error handler function using set_error_handler(), to revert to the previous error handler (which could be the built-in or a user defined function) See also error_reporting(), set_error_handler(), trigger_error(). 它有一个例子,可以试试另外,前端显示最好不要用set_time_limit,没有必要的时候,尽量不要用它
      

  6.   

    “可能是sql server超负荷的”,所以代码错误是停留在mssql_query($query)上,
    所以这个方法:
    if(!$rresult = mssql_query($query) ){
    echo "系统忙,稍后在试";exit;
    }
    不行
      

  7.   

    //用户自定义错误处理过程
    //当发生错误时,在一个自定义的表格里显示错误信息,并自动发一封邮件到技术支持人员set_error_handler("user_define_error_handle");function user_define_error_handle($errorNo, $errorMessage, $errorFile = __FILE__, $errorLine = __LINE__)
    {
    $errorContent = "<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
          <tr>
        <td background=\"images/bk_head.jpg\"><img src=\"images/error.gif\"></td>
      </tr>
          <tr>
       <td background=\"images/bk_main.jpg\">
      <B>ERROR:</B> $errorMessage
              <P>Please try again, or contact us and tell us that 
              the error occurred in line ".$errorLine." of file '".$errorFile."'";
        if ($errorNo == E_USER_ERROR || $errorNo == E_ERROR)
        {
          $errorContent .= "<P>This error was fatal, program ending";
          $errorContent .= "</td></tr></table><br>";
          echo $errorContent;
          exit;
        } 
    $errorContent .= "</td></tr></table><br>";
    echo $errorContent;
    //send a mail to somebody
    include_once('mail/htmlMimeMail.php');
    $mail = new htmlMimeMail();

    $domain = "a1-battery.co.uk";
    $to_name = "to_name";
    $to_email_address = "[email protected]";
    $from_email_address = "[email protected]";
    $subject = "there have some error in the website";
    $text = $errorContent;
    $html = $errorContent;
    $mail->setHtml($html, $text);
    $mail->setReturnPath($to_email_address);
    $mail->setFrom($from_name . '<' . $from_email_address . '>');
    $mail->setSubject($subject);
    $mail->setHeader('X-Mailer', 'HTML Mime mail class (http://www.phpguru.org)');
    $result = $mail->send(array($to_name . '<' . $to_email_address . '>'), 'smtp');
    if (!$result) {
    print_r($mail->errors);
    } else {
    //echo 'Mail sent!';
    //include('ok.htm');
    }
    }
      

  8.   

    : hahawen(变态的大龄青年) (
    不行啊,好像要用到trigger_error,但我不知道trigger_error要放在那里
    if(!$rresult = mssql_query($query) ){
      trigger_error("错误",
          FATAL);
    }
    不行
      

  9.   

    error_reporting(0);
    set_magic_quotes_runtime(0);
    禁止错误4板还不能用try之类的东西捕捉错误,5版可以了