Announcement

Collapse
No announcement yet.

Long Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Long Script

    I have a script that is rather long because it does a few database look ups and several functions for each product in our store. I am just curious if anyone has advice on how to manage something that runs longer than 90 seconds.
    Chris Dye
    http://www.kseriesparts.com

    #2
    You will have to do some sort of refresh or reload to keep resetting the 'timer'.

    In the LSK there is source for an import or export module which demonstrates one technique.

    In our Optimizer module, we use a meta-refresh technique which reloads the page as needed.

    In general, you must save state for current operations in a database table or a file so that when the 'page' is reloaded and the script restarted, you can pick up where you left off.
    Gordon Currie
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit Any Document Easily | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Our export module uses javascript combined with some current state / resume code in the module to allow it to appear to be one long export job, but in reality it is multiple requests that occur, repeating before the globaltimeout value is reached, so that the job can complete without hitting the timeout. Also, and more importantly, without requiring the Empresa timeout or the web server connection timeout to be raised to some large number to let a long running single job complete. Long timeouts are a risk to the server/site as it lets dropped connections or hackers hang connections open doing nothing in an attempt to exhaust all the available connections for legit traffic. The longer the connection timeout, the easier that is.

      David Hubbard
      CIO
      Miva
      [email protected]
      http://www.miva.com

      Comment


        #4
        would it make sense if a php program doing more would take 30 seconds versus the Miva one that times out at 90?

        the php program it is a very similar program to what I was building in Miva but I can't find a good way to work around the Miva time out right now.
        Last edited by K Series Parts; 06-10-16, 09:45 AM.
        Chris Dye
        http://www.kseriesparts.com

        Comment


          #5
          A module in a store may be doing far more behind the scenes than a php script written to perform one specific task; could be anything, from checking access permissions, logging said access to the operating system, operating against inventory, checking active/inactive, whatever the case may be, where the php script is likely written to perform a very specific task with no overhead. Having a php app talk to your payment application's database is a big security risk by the way.
          David Hubbard
          CIO
          Miva
          [email protected]
          http://www.miva.com

          Comment


            #6
            I have taken steps to protect it and also it is why I was working on bring it into Miva but the timeout issue is a big deal. I am going to work on some ways around it but how it works the solution isn't obvious right now.
            Chris Dye
            http://www.kseriesparts.com

            Comment


              #7
              is there a performance difference between just doing a while loop versus a while loop, building an array, and then doing a foreach loop?
              Chris Dye
              http://www.kseriesparts.com

              Comment


                #8
                I have been able to speed up loading my script but I am thinking about implementing pagination to also help the load times. I played around with it a bit but can't seem to figure out the correct href code to make it work, anyone have any tips for me?
                Chris Dye
                http://www.kseriesparts.com

                Comment


                  #9
                  Without knowing what's happening inside the loop it's difficulty to make recommendations to speed it up. Also are you doing this in a page template or module?

                  Also are you outputting directly to the browser display, or creating a file?

                  As for making your script refresh you can implement this in one of two ways. Either by looping through a fixed number of times per pass that's known not to time out (e.g. 200 times) or by checking the clock each time through the loop for a time out value. (e.g. 30 seconds)

                  Either ways, you will exit the loop and then have the program call itself usually via javascript url, passing the last record processed

                  In a page template.
                  http://www.domain.com/merchant.mvc?s...lastrecord=200

                  If directly in a module
                  http://www.domain.com/path/mymodule.mvc?lastrecord=200




                  Ray Yates
                  "If I have seen further, it is by standing on the shoulders of giants."
                  --- Sir Isaac Newton

                  Comment

                  Working...
                  X