Welcome Guest, Not a member yet? Register   Sign In
Display interim, processing-intensive page ASAP
#1

[eluser]CodeIgniterNewbie[/eluser]
I have a page that usually goes from, say, Page-A to Page-C, assuming the background processes executed by cron is able to do its job fast enough. If the background processes are not fast enough, then the page goes from Page-A to Page-B (to do the processing intensive work; this just shows a "please wait while we do some processing" page) to Page-C.

I want Page-B to show immediately. I'm using Smarty. I display the template file, then do the processing. In some cases, Page-B will display quickly, then do the processing, then redirect to Page-C. Sometimes, it seems like the view is stuck at Page-A, does the processing of Page-B, skips displaying Page-B, then goes straight to Page-C.

I want Page-B to display instantly. I've tried putting flush() right after calling the Smarty template; doesn't seem to do much good.

Suggestions?
#2

[eluser]bubbafoley[/eluser]
You're actually going to need 4 pages. The new page (Page-A1) will just do the processing and not show any output. Page-B needs to check if processing has been done already and if not use cUrl with a timeout of 1 second to kick off the processing asynchronously, then go to Page-C if processing is complete otherwise show Page-B. Then set Page-B to refresh itself every 2 or 3 seconds.

It would work something like this:

Page-A:
=====================================
set session variable "processed"=FALSE
redirect to Page-B

Page-A1:
=====================================
do processing
set session variable "processed"=TRUE
set session variable "processing"=FALSE

Page-B:
======================================
if ( ! "processed" AND ! "processing")
{
set session variable "processing"=TRUE
cUrl(Page-A1, timeout = 1 sec)

}
elseif ( "processed" )
{
redirect to Page-C
}
show_waiting_page(refresh = 3 sec)


Page-C
======================================
Ta-Da
#3

[eluser]CodeIgniterNewbie[/eluser]
@bubbafoley - how does adding Page-A1 make Page-B appear faster?
#4

[eluser]SimonH[/eluser]
Hi,

maybe a little bit of a different approach, however you could use an AJAX request on page B to check whether the processing is done and / or kick of the processing. This way you will be certain that the processing is only started once Page B has loaded because you can use JQuery (for example) to execute said AJAX call once the document has loaded.

Hope this helps.
#5

[eluser]bubbafoley[/eluser]
[quote author="CodeIgniterNewbie" date="1298866009"]@bubbafoley - how does adding Page-A1 make Page-B appear faster?[/quote]

If Page-B did all of the processing then it would have to wait until all that processing was finished before displaying any output. Doing the processing via cUrl with a timeout of 1 second tells Page-B not to wait for the processing to finish before sending output.

[quote author="SimonH" date="1298921954"]Hi,

maybe a little bit of a different approach, however you could use an AJAX request on page B to check whether the processing is done and / or kick of the processing. This way you will be certain that the processing is only started once Page B has loaded because you can use JQuery (for example) to execute said AJAX call once the document has loaded.

Hope this helps.[/quote]

This works too.




Theme © iAndrew 2016 - Forum software by © MyBB