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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neil Zanella

    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
  • Von Heler

    #2
    Re: require_once and fatal errors... automatic sleep and try again anyone?

    On 28 Aug 2004, much to the astonishment of all present at comp.lang.php,
    Neil Zanella blurted:
    [color=blue]
    > 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
    >[/color]

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

    Comment

    • Chung Leong

      #3
      Re: require_once and fatal errors... automatic sleep and try again anyone?

      "Neil Zanella" <nzanella@cs.mu n.ca> wrote in message
      news:b68d2f19.0 408272237.620eb e71@posting.goo gle.com...[color=blue]
      > 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.[/color]

      Use include_once() instead. That generates a warning instead of a fatal
      error when it fails. Suppress the warning with @, then use
      get_included_fi les() to see if the file was included.
      [color=blue]
      > 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?[/color]

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


      Comment

      • Neil Zanella

        #4
        Re: require_once and fatal errors... automatic sleep and try again anyone?

        Thanks, your suggestion seems like the best solution to the
        problem. Here is the code:

        <?php

        while (!in_array('DB. php',
        array_map('base name', get_included_fi les()))) {
        @include_once(' DB.php');
        usleep(100000);
        }

        echo 'finally included!!!';

        ?>

        Regards,

        Neil

        "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
        [color=blue]
        > Use include_once() instead. That generates a warning
        > instead of a fatal error when it fails. Suppress the
        > warning with @, then use get_included_fi les() to see
        > if the file was included.
        >[color=green]
        > > 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?[/color]
        >
        > Don't know. Probably an issue at the OS level.[/color]

        Comment

        Working...