Script Reloading Issue

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

    Script Reloading Issue

    I have a PHP framework that integrates buffering and sessions among
    other things and I'm having a problem where my script will get reloaded
    2 or 3 times before being output to the browser. I haven't found any
    other references to this sort of problem so I thought I'd try here.

    I do most my development on a Windows XP Pro desktop (running XAMPP),
    so I thought maybe it was an XP-specific problem, but I just tried it
    on my linux host and same thing. Here's a little log that helps
    illustrate:

    Session|Script Basename Datetime Split Time
    -----------------------------------------------------------------------------------------
    001|01 test.php [2006 Jun 13 06:27:00] +-----+ ms
    002|01 test.php [2006 Jun 13 06:27:01] +348.15 ms
    003|01 test.php [2006 Jun 13 06:27:01] +265.15 ms

    That's loading the page in Firefox once. Counters in the left column
    are a session and static variable respectively. Other scripts will
    load twice. It's especially problematic where there's something like a
    email trigger involved as it will send off multiple emails where only 1
    is wanted.

    Anyone else encounter anything like this? Could it be a Session or
    buffering problem? Something to do with logging perhaps? And why 2 or
    3 times and not 7 or 8 or 1000? Any insight welcome.

    Puzzled,
    Tom

  • Tom

    #2
    Re: Script Reloading Issue

    I've narrowed my problem a bit. As part of my framework, I set various
    head variables (e.g. title, character-encoding, etc.) in an array
    ($HEAD) and then echo them by calling a function print_html_head ($HEAD)
    which returns the document declaration and head portion of my web page
    as a string.

    So far so good. But when I now echo this string, the page reloads
    three times. To wit, breakpoint before echo statement, no reload.
    After echo statement, page reloads three times. Note also: the output
    is buffered, so it's not being output in the browser yet. And this is
    the first echo statement in the script.

    Anybody have any idea what this would be symptomatic of?

    Thanks,
    Tom


    Tom wrote:[color=blue]
    > I have a PHP framework that integrates buffering and sessions among
    > other things and I'm having a problem where my script will get reloaded
    > 2 or 3 times before being output to the browser. I haven't found any
    > other references to this sort of problem so I thought I'd try here.
    >
    > I do most my development on a Windows XP Pro desktop (running XAMPP),
    > so I thought maybe it was an XP-specific problem, but I just tried it
    > on my linux host and same thing. Here's a little log that helps
    > illustrate:
    >
    > Session|Script Basename Datetime Split Time
    > -----------------------------------------------------------------------------------------
    > 001|01 test.php [2006 Jun 13 06:27:00] +-----+ ms
    > 002|01 test.php [2006 Jun 13 06:27:01] +348.15 ms
    > 003|01 test.php [2006 Jun 13 06:27:01] +265.15 ms
    >
    > That's loading the page in Firefox once. Counters in the left column
    > are a session and static variable respectively. Other scripts will
    > load twice. It's especially problematic where there's something like a
    > email trigger involved as it will send off multiple emails where only 1
    > is wanted.
    >
    > Anyone else encounter anything like this? Could it be a Session or
    > buffering problem? Something to do with logging perhaps? And why 2 or
    > 3 times and not 7 or 8 or 1000? Any insight welcome.
    >
    > Puzzled,
    > Tom[/color]

    Comment

    • Rik

      #3
      Re: Script Reloading Issue

      Tom wrote:[color=blue]
      > I've narrowed my problem a bit. As part of my framework, I set
      > various
      > head variables (e.g. title, character-encoding, etc.) in an array
      > ($HEAD) and then echo them by calling a function
      > print_html_head ($HEAD)
      > which returns the document declaration and head portion of my web page
      > as a string.
      >
      > So far so good. But when I now echo this string, the page reloads
      > three times. To wit, breakpoint before echo statement, no reload.
      > After echo statement, page reloads three times. Note also: the output
      > is buffered, so it's not being output in the browser yet. And this is
      > the first echo statement in the script.
      >
      > Anybody have any idea what this would be symptomatic of?[/color]

      Incorrectly flushing the buffer?
      What functions do you use to send the buffer?

      Grtz,
      --
      Rik Wasmus


      Comment

      • Tom

        #4
        Re: Script Reloading Issue

        I use the following code to flush the buffer as suggested at
        PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


        while (ob_get_level() > 0)
        {
        ob_end_flush();
        }

        However, I just noticed a comment:

        "Apart from being mostly redundant, ob_end_flush() can be downright
        damaging in some weird cases..."

        So maybe it has something to do with that.

        What I find odd is: if I comment out the echo statement (thus removing
        the document statement and head section), the script loads normally. I
        thought maybe it was a syntax error, but I've run the XHTML output
        through the w3C validator and it validates.

        I've also tried removing the buffer flush all together and just letting
        the end of the script flush it, but that doesn't seem to solve the
        reloading problem.

        I'll tinker and tweak further. Anyone else have this problem with
        outputing a web page's head section?

        Tom



        Rik wrote:
        [color=blue]
        > Incorrectly flushing the buffer?
        > What functions do you use to send the buffer?
        >
        > Grtz,
        > --
        > Rik Wasmus[/color]

        Comment

        • Tom

          #5
          Re: Script Reloading Issue

          Just for the record, I think I've resolved this.

          The problem seems to be my <HEAD> output function. It contains 2
          placeholder statements for links to an external js and css file. If I
          didn't pass a value, it would print out something like this:

          <link href="" type="text/css" rel="stylesheet " />

          These blank href values in these statements were causing my script to
          reload (in Firefox, at least).

          Anyway, now I know. Hopefully, this will save some trouble someday for
          anyone else having this problem.

          Tom



          Tom wrote:[color=blue]
          > I've narrowed my problem a bit. As part of my framework, I set various
          > head variables (e.g. title, character-encoding, etc.) in an array
          > ($HEAD) and then echo them by calling a function print_html_head ($HEAD)
          > which returns the document declaration and head portion of my web page
          > as a string.
          >
          > So far so good. But when I now echo this string, the page reloads
          > three times. To wit, breakpoint before echo statement, no reload.
          > After echo statement, page reloads three times. Note also: the output
          > is buffered, so it's not being output in the browser yet. And this is
          > the first echo statement in the script.
          >
          > Anybody have any idea what this would be symptomatic of?
          >
          > Thanks,
          > Tom
          >
          >
          > Tom wrote:[color=green]
          > > I have a PHP framework that integrates buffering and sessions among
          > > other things and I'm having a problem where my script will get reloaded
          > > 2 or 3 times before being output to the browser. I haven't found any
          > > other references to this sort of problem so I thought I'd try here.
          > >
          > > I do most my development on a Windows XP Pro desktop (running XAMPP),
          > > so I thought maybe it was an XP-specific problem, but I just tried it
          > > on my linux host and same thing. Here's a little log that helps
          > > illustrate:
          > >
          > > Session|Script Basename Datetime Split Time
          > > -----------------------------------------------------------------------------------------
          > > 001|01 test.php [2006 Jun 13 06:27:00] +-----+ ms
          > > 002|01 test.php [2006 Jun 13 06:27:01] +348.15 ms
          > > 003|01 test.php [2006 Jun 13 06:27:01] +265.15 ms
          > >
          > > That's loading the page in Firefox once. Counters in the left column
          > > are a session and static variable respectively. Other scripts will
          > > load twice. It's especially problematic where there's something like a
          > > email trigger involved as it will send off multiple emails where only 1
          > > is wanted.
          > >
          > > Anyone else encounter anything like this? Could it be a Session or
          > > buffering problem? Something to do with logging perhaps? And why 2 or
          > > 3 times and not 7 or 8 or 1000? Any insight welcome.
          > >
          > > Puzzled,
          > > Tom[/color][/color]

          Comment

          Working...