Web Hosting Forums

Results 1 to 6 of 6

This is a discussion on Secondary page redirect in the Hosting Talk & Chit-chat forum
I don't really know if there's a name for what I'd like to do but here is my desire: Daily I need to quiesce my ...

  1. #1
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,503

    Secondary page redirect

    I don't really know if there's a name for what I'd like to do but here is my desire:

    Daily I need to quiesce my database for a minute or so while I dump it. Mysqldump does this nicely, however my website is still up and running and to my visitors it seems like the website has crashed.

    I'd like to intercept requests and let them know what is going on. I'd also like to automagically continue their request when the dump has completed.

    I know I can intercept the requests with a quick change to my .htaccess file(s), and send it off to a php script. I also know that I can send back to the browser a "hang on for about a minute" page. But now that I've sent a page, how can I redirect their request back to where they originally wanted, with all post and/or get fields intact?

    If I didn't want to send back a "hang on" page, I could just call header("location:<original request uri>") but that defeats the purpose of the whole thing. I'd like to do both.

    Any suggestions?

    Thanks
    Good luck

  2. #2
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    You mean you want to generate one of those pages that says "you'll be redirected in a minute, if your browser doesn't support that, click here"?

    That's done with a header like this in the HTML code:
    HTML Code:
    <META HTTP-EQUIV="refresh" CONTENT="60;URL=http://ron's site.com/the page to redirect to">
    That gets you a GET request. I doubt there's a similar simple way to make a POST. If there isn't, you could do a POST via a JavaScript timer that makes an XMLHttpRequest. But first I'd wonder if you can't work with only GET for this.


    But if it's done so quickly, why do you shut down the site so completely? You could also run mysqldump with --lock-all-tables (-x). That creates a global read lock during the dump to insure consistency while your site can still read from the database. Any attempts to change will be made to wait by MySQL till the dump is done.

    If that wait takes too long, you might build a timeout in your scripts that sends some initial output to the user, like "Some patience please, you happen to catch us in the middle of a backup. Back within a minute.", followed by some ".." occasionally to show both the user and his browser that you're still at it. You biggest challenge will be to send this in a way that doesn't disrupt your layout once you've completed the page.
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

  3. #3
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,503
    The problem lies with visitors who are in the middle of posting to the database. Currently it just hangs for them. Some browsers my time out.

    I can probably go into the code and just do what I do when they fail validation. I return the form to them still filled in, so they don't lose their work.

    Instead of an error code I could give a "Database maintenace in progress. This takes approximately 90 seconds, so hit "submit" again in about 30 seconds." message.

    Hmmm, that might work for me... but I was hoping to create some sort of a generic script that I could insert into every situation (through .htaccess) that reads any database.
    Good luck

  4. #4
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    Quote Originally Posted by Ron View Post
    I can probably go into the code and just do what I do when they fail validation. I return the form to them still filled in, so they don't lose their work.

    Instead of an error code I could give a "Database maintenace in progress. This takes approximately 90 seconds, so hit "submit" again in about 30 seconds." message.
    Yeah, that sounds like an ok solution.

    Hmmm, that might work for me... but I was hoping to create some sort of a generic script that I could insert into every situation (through .htaccess) that reads any database.
    But its a fairly big leap from a GET or POST to a database write; the two aren't very directly related. It seems to me that a solution closer to the database is far more natural. You can still build it in a way that is generic to your own code, no? (I assume it uses a central database class and a central validation class.)

    BTW, you said "reads" again. Are reads a problem too? If so, any idea why?
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

  5. #5
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,503
    Reads are locked out during the update as well. I'm sure that the forum updates page views all the time.

    I do appreciate your thoughts about it, Wim, but I'd like to try and investigate what would be required to make a script that I can direct any request to, that would both return a reply and then forward the request along once the update is done. I'd like to do this without sending any extraneous data back to the browser if possible.

    BTW, to perhaps foreshorten the cycle, I do know how, and have a way to detect when the update has completed.
    Good luck

  6. #6
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Just thinking out loud, but what if you recreated the post in a form that is hidden to the user (i.e. just use hidden fields or use display:none on it) then use JavaScript to 'document.getElementById("waitform").sub mit()' after a set time? As long as the user has JavaScript enabled it will repost the data if you use method="post" in the form.

    If you want to get really creative you could use JavaScript to hide the form after it is created, allowing non-JS users to chick submit (provide them an appropriate message, of course) while doing it automatically for users that have JS enabled.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •