Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

of IMAP and recovering from Fatal Errors

Status
Not open for further replies.

TheJhereg

Programmer
Nov 12, 2001
31
US
I'm building a page to pull some statistics on several (43 actually) mailboxes by connecting to their imap server and requesting the all headers in the inbox (using imap_headers ($mbox)). Though, really, all I'm trying to get is the number of unread/unseen pieces of mail and the date sent of the oldest piece.

The problem is that the imap_headers function seems to timeout on several email user boxes. Always this error is "Fatal Error: Maximum execution time of 120 seconds exceeded."

The first question is how do I handle that error gracefully, and continue on with other operations (like moving on to another page/iteration of the loop)?

Secondly, if anyone has a better way of doing this, Please, I'm begging for suggestions. The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
A bump and more information:

I've designed an error handler to capture this error and move on, but unfortunately, it too suffers from the time exceeded.

What I'm now looking for is a way to catch this errror before it brings the site to a dead stop.

Here's the code:

Code:
// Code generating the error.
set_time_limit(120) ;
$headersThing =  imap_headers ($mbox);

Error handler:
Code:
// set the error reporting level for this script
error_reporting (E_ERROR  | E_CORE_ERROR  | E_WARNING | E_CORE_WARNING | E_PARSE );

// error handler function
function myErrorHandler ($errno, $errstr, $errfile, $errline) {
	set_time_limit(0) ;
  switch ($errno) {
  case E_CORE_ERROR:
  case E_ERROR:
    echo &quot;HI Everyone: <b>FATAL</b> [$errno] $errstr<br>\n&quot;;
    echo &quot;  Fatal error in line &quot;.$errline.&quot; of file &quot;.$errfile;
    echo &quot;, PHP &quot;.PHP_VERSION.&quot; (&quot;.PHP_OS.&quot;)<br>\n&quot;;
    echo &quot;Aborting...<br>\n&quot;;
    exit -1;
    break;
  case E_WARNING:
  case E_CORE_WARNING:
    echo &quot;HI Everyone: <b>ERROR</b> [$errno] $errstr<br>\n&quot;;
    break;
  case E_PARSE:
    echo &quot;HI Everyone: <b>WARNING</b> [$errno] $errstr<br>\n&quot;;
    break;
  case E_NOTICE:
  		break; 
  default:
    echo &quot;Unkown error type: [$errno] $errstr<br>\n&quot;;
    break;
  }
}

$old_error_handler = set_error_handler(&quot;myErrorHandler&quot;);

I would think this would work, however it generates more execution time errors.

Output:

Code:
Fatal error: Maximum execution time of 120 seconds exceeded in C:\Inetpub\[URL unfurl="true"]wwwroot\imap\USBoxes\boxloop.php[/URL] on line 33

Fatal error: Maximum execution time of 120 seconds exceeded in C:\Inetpub\[URL unfurl="true"]wwwroot\imap\include\errors.php[/URL] on line 8

Line 33 is the imap_headers call from above, and line 8 is
Code:
function myErrorHandler ($errno, $errstr, $errfile, $errline) {
Anyone know of a way to make the error handler function correctly, instead of generating the error when it's called? The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top