Does PHP "cache" scripts?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StevePBurgess@gmail.com

    Does PHP "cache" scripts?

    A really simple script is driving me up the wall.

    I have a very simply facility on a website to allow the user to reorder
    items in a database table as she wishes by clicking a link that (in
    this case) says "MOVE UP" and links to the script below.

    This script snippet that does all the work is shown - the database
    connection is established and after doing its work the script returns
    the user to the referring page.

    ---------------------------------------------
    $sql="select DisplayOrder from CreditType where Id=" . $credcat;
    $result=mysql_q uery($sql);
    $row=mysql_fetc h_row($result);

    $sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
    Id=" . $credcat;

    mysql_query($sq l);

    $sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
    DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;

    mysql_query($sq l);
    --------------------------------------------

    On my own server this works perfectly - but when I upload it to my
    client's shared server it sometimes works and sometimes doesn't. It is
    intermittent.

    Could PHP be returning a cached result of the script? If no, what on
    earth can be happening? If yes, can I stop this from happning from the
    script (I can't change any settings on the shared host).

    Many thanks.
    Steve

  • Andy Hassall

    #2
    Re: Does PHP &quot;cache&quo t; scripts?

    On 14 Sep 2006 13:41:23 -0700, StevePBurgess@g mail.com wrote:
    >On my own server this works perfectly - but when I upload it to my
    >client's shared server it sometimes works and sometimes doesn't. It is
    >intermittent .
    How do you mean it doesn't work, exactly?
    >Could PHP be returning a cached result of the script? If no, what on
    >earth can be happening?
    PHP doesn't cache scripts. There's extensions like APC that cache the compiled
    form of the script, but that doesn't (or shouldn't) have anything to with the
    results.

    MySQL can be configured to have a cache, but I don't know much about that.

    Your browser can cache, but you can send headers that advise the browser not
    to cache (look up the Pragma HTTP header).

    Your ISP may have "transparen t" caching proxies; ntl: are infamous for that.

    It could be something much simpler; I don't see any error checking on the
    mysql_query calls.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • StevePBurgess@gmail.com

      #3
      Re: Does PHP &quot;cache&quo t; scripts?

      Hi - thanks for the reply. The script is stripped bare - there is error
      checking on the actual script and all queries work fine.

      When I say it doesn't work - I just mean the user clicks on the link
      and is returned almost immediately to the page as if nothing has
      happened.

      I have just tried it in Internet Explorer and it seems to work there -
      but sometimes I have to "refresh" the page to see the effect, sometimes
      it updates ok.

      In firefox, sometimes it works and sometimes it doesn't. When it does,
      the page updates itself to reflect the "move up" - if it doesn't work
      refreshing has no effect.

      If I try the link in firefox and it doesn't work and then close firefox
      down and visit the same link on the same page and then try, it works
      (hence a suspicion of caching or session issues).

      As I say - it works perfectly in all browsers on my dedicated server.
      Exactly the same script - just a different server - so I am assuming it
      is a server issue.

      I'm flummoxed!

      Best,
      Steve


      Andy Hassall wrote:
      On 14 Sep 2006 13:41:23 -0700, StevePBurgess@g mail.com wrote:
      >
      On my own server this works perfectly - but when I upload it to my
      client's shared server it sometimes works and sometimes doesn't. It is
      intermittent.
      >
      How do you mean it doesn't work, exactly?
      >
      Could PHP be returning a cached result of the script? If no, what on
      earth can be happening?
      >
      PHP doesn't cache scripts. There's extensions like APC that cache the compiled
      form of the script, but that doesn't (or shouldn't) have anything to with the
      results.
      >
      MySQL can be configured to have a cache, but I don't know much about that.
      >
      Your browser can cache, but you can send headers that advise the browser not
      to cache (look up the Pragma HTTP header).
      >
      Your ISP may have "transparen t" caching proxies; ntl: are infamous for that.
      >
      It could be something much simpler; I don't see any error checking on the
      mysql_query calls.
      >
      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • Colin McKinnon

        #4
        Re: Does PHP &quot;cache&quo t; scripts?

        StevePBurgess@g mail.com wrote:
        A really simple script is driving me up the wall.
        >
        I have a very simply facility on a website to allow the user to reorder
        items in a database table as she wishes by clicking a link that (in
        this case) says "MOVE UP" and links to the script below.
        >
        This script snippet that does all the work is shown - the database
        connection is established and after doing its work the script returns
        the user to the referring page.
        <snip>
        On my own server this works perfectly - but when I upload it to my
        client's shared server it sometimes works and sometimes doesn't. It is
        intermittent.
        >
        hmmm, "client's shared server". I can read so much into that.

        Go get a copy of iehttpheaders for MSIE or tamper data for firefox and find
        out for yourself.
        Could PHP be returning a cached result of the script?
        No. Not unless you wrote it that way.
        If no, what on
        earth can be happening? If yes, can I stop this from happning from the
        script (I can't change any settings on the shared host).
        The webserver could be returning bad caching information. You may be
        accessing it through an overzealous cache - you're code didn't contain any
        cache instructions.

        C.

        Comment

        • Kim Hunter

          #5
          Re: Does PHP &quot;cache&quo t; scripts?

          i would compare the config on both servers, (maybe registered globals is
          on on the client).

          StevePBurgess@g mail.com wrote:
          A really simple script is driving me up the wall.
          >
          I have a very simply facility on a website to allow the user to reorder
          items in a database table as she wishes by clicking a link that (in
          this case) says "MOVE UP" and links to the script below.
          >
          This script snippet that does all the work is shown - the database
          connection is established and after doing its work the script returns
          the user to the referring page.
          >
          ---------------------------------------------
          $sql="select DisplayOrder from CreditType where Id=" . $credcat;
          $result=mysql_q uery($sql);
          $row=mysql_fetc h_row($result);
          >
          $sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
          Id=" . $credcat;
          >
          mysql_query($sq l);
          >
          $sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
          DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;
          >
          mysql_query($sq l);
          --------------------------------------------
          >
          On my own server this works perfectly - but when I upload it to my
          client's shared server it sometimes works and sometimes doesn't. It is
          intermittent.
          >
          Could PHP be returning a cached result of the script? If no, what on
          earth can be happening? If yes, can I stop this from happning from the
          script (I can't change any settings on the shared host).
          >
          Many thanks.
          Steve
          >

          Comment

          • NC

            #6
            Re: Does PHP &quot;cache&quo t; scripts?

            StevePBurgess@g mail.com wrote:
            >
            This script snippet that does all the work is shown - the database
            connection is established and after doing its work the script returns
            the user to the referring page.
            ....
            On my own server this works perfectly - but when I upload it to my
            client's shared server it sometimes works and sometimes doesn't.
            It is intermittent.
            Check register_global s setting on the two servers. Maybe something
            writes over your GET/POST variables or vice versa...

            Also, how do you handle MySQL errors? The behavior you are observing
            is consistent with queries not being executed (which could happen when
            your MySQL server is overloaded). The script tries to connect to the
            MySQL server, gets an error, fails to execute the queries due to no
            connection and redirects...
            Could PHP be returning a cached result of the script?
            No, but it is possible that the hosting company does. It is unlikely
            though, because the problem is intermittent...

            Cheers,
            NC

            Comment

            • Jerry Stuckle

              #7
              Re: Does PHP &quot;cache&quo t; scripts?

              StevePBurgess@g mail.com wrote:
              Hi - thanks for the reply. The script is stripped bare - there is error
              checking on the actual script and all queries work fine.
              >
              When I say it doesn't work - I just mean the user clicks on the link
              and is returned almost immediately to the page as if nothing has
              happened.
              >
              I have just tried it in Internet Explorer and it seems to work there -
              but sometimes I have to "refresh" the page to see the effect, sometimes
              it updates ok.
              >
              In firefox, sometimes it works and sometimes it doesn't. When it does,
              the page updates itself to reflect the "move up" - if it doesn't work
              refreshing has no effect.
              >
              If I try the link in firefox and it doesn't work and then close firefox
              down and visit the same link on the same page and then try, it works
              (hence a suspicion of caching or session issues).
              >
              As I say - it works perfectly in all browsers on my dedicated server.
              Exactly the same script - just a different server - so I am assuming it
              is a server issue.
              >
              I'm flummoxed!
              >
              Best,
              Steve
              >
              >
              Andy Hassall wrote:
              >
              >>On 14 Sep 2006 13:41:23 -0700, StevePBurgess@g mail.com wrote:
              >>
              >>
              >>>On my own server this works perfectly - but when I upload it to my
              >>>client's shared server it sometimes works and sometimes doesn't. It is
              >>>intermittent .
              >>
              >How do you mean it doesn't work, exactly?
              >>
              >>
              >>>Could PHP be returning a cached result of the script? If no, what on
              >>>earth can be happening?
              >>
              >PHP doesn't cache scripts. There's extensions like APC that cache the compiled
              >>form of the script, but that doesn't (or shouldn't) have anything to with the
              >>results.
              >>
              >MySQL can be configured to have a cache, but I don't know much about that.
              >>
              >Your browser can cache, but you can send headers that advise the browser not
              >>to cache (look up the Pragma HTTP header).
              >>
              >Your ISP may have "transparen t" caching proxies; ntl: are infamous for that.
              >>
              >It could be something much simpler; I don't see any error checking on the
              >>mysql_query calls.
              >>
              >>--
              >>Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
              >>http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
              >
              >
              Andy,

              Not necessarily a server issue. It could be anything between the server
              and your system that's caching the page.

              But it definitely sounds like a caching issue. Nothing in PHP or MySQL
              would do this.

              You might try adding a random string as a parameter, such as:


              where you get the value from microtime() or similar. This should take
              care of caching issues.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • StevePBurgess@gmail.com

                #8
                Re: Does PHP &quot;cache&quo t; scripts?


                NC wrote:
                Also, how do you handle MySQL errors? The behavior you are observing
                is consistent with queries not being executed (which could happen when
                your MySQL server is overloaded). The script tries to connect to the
                MySQL server, gets an error, fails to execute the queries due to no
                connection and redirects..
                Thanks - there are definitely no sql errors (there is error checking on
                the mysql queries - I removed it here for brevity.

                Comment

                • StevePBurgess@gmail.com

                  #9
                  Re: Does PHP &quot;cache&quo t; scripts?


                  Kim Hunter wrote:
                  i would compare the config on both servers, (maybe registered globals is
                  on on the client).
                  >
                  All the variables used in the script are sourced from the relevant
                  $_POST or $_GET. The script was designed for register_global s to be
                  off.

                  I'll check though it there are any discrepancies in the config that
                  might cause this problem.

                  Comment

                  • StevePBurgess@gmail.com

                    #10
                    Re: Does PHP &quot;cache&quo t; scripts?

                    Thanks everyone. I'll try your suggestions tonight and post back.

                    Steve

                    Comment

                    • Petr Vileta

                      #11
                      Re: Does PHP &quot;cache&quo t; scripts?

                      StevePBurgess@g mail.com wrote:
                      Kim Hunter wrote:
                      >i would compare the config on both servers, (maybe registered
                      >globals is on on the client).
                      >>
                      >
                      All the variables used in the script are sourced from the relevant
                      $_POST or $_GET. The script was designed for register_global s to be
                      off.
                      >
                      I'll check though it there are any discrepancies in the config that
                      might cause this problem.
                      I'm not sure but try to flush tables after all updates.

                      $sql="select DisplayOrder from CreditType where Id=" . $credcat;
                      $result=mysql_q uery($sql);
                      $row=mysql_fetc h_row($result);

                      $sql="update CreditType set DisplayOrder=" . (($row[0])-1) . " where
                      Id=" . $credcat;
                      mysql_query($sq l);

                      $sql="update CreditType set DisplayOrder=" . ($row[0]) ." where
                      DisplayOrder=" . (($row[0])-1) . " and Id<>" . $credcat;
                      mysql_query($sq l);

                      # this can resolve your problem
                      $sql="flush tables";
                      mysql_query($sq l);


                      --

                      Petr Vileta, Czech republic
                      (My server rejects all messages from Yahoo and Hotmail. Send me your mail
                      from another non-spammer site please.)


                      Comment

                      • StevePBurgess@gmail.com

                        #12
                        Re: Does PHP &quot;cache&quo t; scripts?

                        I have added the random number to the URL and the script now works
                        perfectly. In Internet Explorer. The database is updated and on return
                        to the list page the correct order is reflected.

                        In Firefox it still won't work. The database doesn't get updated and
                        the random number in the url doesn't change or get updated.

                        As my client uses IE I guess it's not that big a deal - but it is
                        frustrating as Firefox is my preferred browser.

                        Any further thoughts?

                        Comment

                        • StevePBurgess@gmail.com

                          #13
                          Re: Does PHP &quot;cache&quo t; scripts?

                          I've just run the script in Firefox again and noticed something odd.
                          There are two links, thus:

                          MOVE UP - MOVE DOWN

                          When I click on MOVE UP the database isn't updated but I get this in
                          the address box when the script returns me to the main page:



                          When I click MOVE DOWN the database isn't updated and I get this:



                          if I click MOVE UP again I get



                          which is the same as the first time I clicked it. The r= variable is
                          the unix time stamp so either firefox is caching the page or my server
                          is somehow going back in time! ;o)

                          If I leave it for a while and try again, the number is updated to a new
                          number (and sometimes the database is updated and the order on the
                          credits page is changed).

                          Steve



                          StevePBurg...@g mail.com wrote:
                          I have added the random number to the URL and the script now works
                          perfectly. In Internet Explorer. The database is updated and on return
                          to the list page the correct order is reflected.
                          >
                          In Firefox it still won't work. The database doesn't get updated and
                          the random number in the url doesn't change or get updated.
                          >
                          As my client uses IE I guess it's not that big a deal - but it is
                          frustrating as Firefox is my preferred browser.
                          >
                          Any further thoughts?

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Does PHP &quot;cache&quo t; scripts?

                            StevePBurgess@g mail.com wrote:
                            I've just run the script in Firefox again and noticed something odd.
                            There are two links, thus:
                            >
                            MOVE UP - MOVE DOWN
                            >
                            When I click on MOVE UP the database isn't updated but I get this in
                            the address box when the script returns me to the main page:
                            >

                            >
                            When I click MOVE DOWN the database isn't updated and I get this:
                            >

                            >
                            if I click MOVE UP again I get
                            >

                            >
                            which is the same as the first time I clicked it. The r= variable is
                            the unix time stamp so either firefox is caching the page or my server
                            is somehow going back in time! ;o)
                            >
                            If I leave it for a while and try again, the number is updated to a new
                            number (and sometimes the database is updated and the order on the
                            credits page is changed).
                            >
                            Steve
                            >
                            >
                            >
                            StevePBurg...@g mail.com wrote:
                            >
                            >>I have added the random number to the URL and the script now works
                            >>perfectly. In Internet Explorer. The database is updated and on return
                            >>to the list page the correct order is reflected.
                            >>
                            >>In Firefox it still won't work. The database doesn't get updated and
                            >>the random number in the url doesn't change or get updated.
                            >>
                            >>As my client uses IE I guess it's not that big a deal - but it is
                            >>frustrating as Firefox is my preferred browser.
                            >>
                            >>Any further thoughts?
                            >
                            >
                            Still a caching problem. But not related to PHP. You might get better
                            answers in a group such as alt.html.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • StevePBurgess@gmail.com

                              #15
                              Re: Does PHP &quot;cache&quo t; scripts?


                              Jerry Stuckle wrote:
                              Still a caching problem. But not related to PHP. You might get better
                              answers in a group such as alt.html.
                              >
                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Thanks. I'll try that.

                              Comment

                              Working...