I have a site I'm working on that uses a cache table to display some info because the query to do it takes too long to run otherwise. Since the data in the cache table will only be updated every so often I'd rather take the hit on that end than on displaying the data.
On to my question:
Is there a way that I can have a long running process (anywhere from 15 seconds to 60 seconds) running in the background of a page where I'm displaying a progress bar to the client? Or even a page where it kicks off a background process that runs while the client continues browsing. I read the best way to do this is with exec(), but that only works with the CGI/CLI enabled and seeing as I'm using a regular web host and not a dedicated server I don't have access to that.
Does anyone have any ideas how I could go about doing this?
Thanks!
Progress bar and long-running processes
Moderator: General Moderators
- aerodromoi
- Forum Contributor
- Posts: 230
- Joined: Sun May 07, 2006 5:21 am
Re: Progress bar and long-running processes
This should be possible usingaphistic wrote: On to my question:
Is there a way that I can have a long running process (anywhere from 15 seconds to 60 seconds) running in the background of a page where I'm displaying a progress bar to the client? Or even a page where it kicks off a background process that runs while the client continues browsing. I read the best way to do this is with exec(), but that only works with the CGI/CLI enabled and seeing as I'm using a regular web host and not a dedicated server I don't have access to that.
Does anyone have any ideas how I could go about doing this?
Thanks!
a) JavaScript or
b) ActionScript (Flash)
aerodromoi
Question: How do you know how long the process is going to take? On a bad day with lots of traffic, or if the server is extra busy, it could take 60 seconds, on a good day it could take 20 seconds. How can you know which point the update is at?
(I'm assuming this is a single query - if it is mulitple queries, you could maybe report back something at the end of each of them, ie: with 5 queries you could say that it's 20% finished after the first one etc.)
What you could do is before the update query starts, set a flag value in a table that says it is running, and have your web pages query this flag before loading - if the flag is set, redirect to a "Updating" page, and refresh every 15 seconds or so via a meta refresh. When the process has finished running, reset the flag. It's a bit clumsy maybe, but I don't know of any other way (Probably Ajax can help you, but I don't know much about it).
(I'm assuming this is a single query - if it is mulitple queries, you could maybe report back something at the end of each of them, ie: with 5 queries you could say that it's 20% finished after the first one etc.)
What you could do is before the update query starts, set a flag value in a table that says it is running, and have your web pages query this flag before loading - if the flag is set, redirect to a "Updating" page, and refresh every 15 seconds or so via a meta refresh. When the process has finished running, reset the flag. It's a bit clumsy maybe, but I don't know of any other way (Probably Ajax can help you, but I don't know much about it).
I really don't know how long the process itself will take. On a slow day it could be no more than a couple seconds but if the data I'm querying from starts getting more involved it could take longer. Yeah, it's a single query that I'm running so I wouldn't be able to return the current status, sadly.GM wrote:Question: How do you know how long the process is going to take? On a bad day with lots of traffic, or if the server is extra busy, it could take 60 seconds, on a good day it could take 20 seconds. How can you know which point the update is at?
(I'm assuming this is a single query - if it is mulitple queries, you could maybe report back something at the end of each of them, ie: with 5 queries you could say that it's 20% finished after the first one etc.)
What you could do is before the update query starts, set a flag value in a table that says it is running, and have your web pages query this flag before loading - if the flag is set, redirect to a "Updating" page, and refresh every 15 seconds or so via a meta refresh. When the process has finished running, reset the flag. It's a bit clumsy maybe, but I don't know of any other way (Probably Ajax can help you, but I don't know much about it).
I do like the idea of setting the flag when it's running and I thought about that myself just so on the pages that use the data I could tell other users that try to access it that it's currently being updated. What I don't know how to do is kick off the query so the client can do other things while the query is running (such as refreshing the page like you mentioned). This would all be easier, I suppose, if I could run it via a cron job or something but I don't have that much access to the server.
Edited:
This is similar to what I'd like to do, but in ASP.Net: http://www.aspfree.com/c/a/VB.NET/Execu ... in-ASPNET/