469,953 Members | 2,400 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

require_once and fatal errors... automatic sleep and try again anyone?

Hello,

I have a PHP page which loads OK 80% of the time. However
the rest of the time I get the following error:

Fatal error: Failed opening required 'DB.php'

This really bugs me, especially since the only reason
this is happeneing seems to be due to server load. I
would like to add code so that instead of displaying
the given error, the PHP code makes the HTTP response
thread simply sleep a little bit (say 4 seconds), and
then retry, and repeat until the file can be opened.

It seems strange to me that server load would prevent
the file from being opened. Anyhow, any ideas on how
I can improve the situation?

Thanks,

Neil
Jul 17 '05 #1
3 2070
On 28 Aug 2004, much to the astonishment of all present at comp.lang.php,
Neil Zanella blurted:
Hello,

I have a PHP page which loads OK 80% of the time. However
the rest of the time I get the following error:

Fatal error: Failed opening required 'DB.php'

This really bugs me, especially since the only reason
this is happeneing seems to be due to server load. I
would like to add code so that instead of displaying
the given error, the PHP code makes the HTTP response
thread simply sleep a little bit (say 4 seconds), and
then retry, and repeat until the file can be opened.

It seems strange to me that server load would prevent
the file from being opened. Anyhow, any ideas on how
I can improve the situation?

Thanks,

Neil


Is the domain you are using for this site using a redirect? If so, I have
had a very similar problem which seemed to be solved by using an absolute
URL path to the include (which is ok as long as it is located above root).
Jul 17 '05 #2
"Neil Zanella" <nz******@cs.mun.ca> wrote in message
news:b6**************************@posting.google.c om...
Hello,

I have a PHP page which loads OK 80% of the time. However
the rest of the time I get the following error:

Fatal error: Failed opening required 'DB.php'

This really bugs me, especially since the only reason
this is happeneing seems to be due to server load. I
would like to add code so that instead of displaying
the given error, the PHP code makes the HTTP response
thread simply sleep a little bit (say 4 seconds), and
then retry, and repeat until the file can be opened.
Use include_once() instead. That generates a warning instead of a fatal
error when it fails. Suppress the warning with @, then use
get_included_files() to see if the file was included.
It seems strange to me that server load would prevent
the file from being opened. Anyhow, any ideas on how
I can improve the situation?


Don't know. Probably an issue at the OS level.
Jul 17 '05 #3
Thanks, your suggestion seems like the best solution to the
problem. Here is the code:

<?php

while (!in_array('DB.php',
array_map('basename', get_included_files()))) {
@include_once('DB.php');
usleep(100000);
}

echo 'finally included!!!';

?>

Regards,

Neil

"Chung Leong" <ch***********@hotmail.com> wrote in message
Use include_once() instead. That generates a warning
instead of a fatal error when it fails. Suppress the
warning with @, then use get_included_files() to see
if the file was included.
It seems strange to me that server load would prevent
the file from being opened. Anyhow, any ideas on how
I can improve the situation?


Don't know. Probably an issue at the OS level.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Justin L. Kennedy | last post: by
11 posts views Thread by Kimmo Laine | last post: by
7 posts views Thread by Ronald Raygun | last post: by
4 posts views Thread by Andrew G. Koptyaev | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.