Re: User interface for process that takess a long time...

From: JGH (johnheim_at_nospam.tds.net)
Date: 05/07/04


Date: Fri, 7 May 2004 19:38:55 +0000 (UTC)

Chris Hope <chris@electrictoolbox.com> wrote in
> I did this once to do something along the lines of what you are
> wanting to do. It worked for me but I can't guarantee it will work for
> you...
>
> set_time_limit(0);
> ignore_user_abort(1);
> register_shutdown_function("foo");
> header("location: bar.php");
> flush();
> exit();
>
> Then there was a function called "foo" (well it wasn't really called
> that but is in this example) which does all the work. The only issue
> then is how to get the progress page to work out if the work is done
> yet.
>
> Ten seconds isn't really a very long time to wait for something to
[...]

Well, the process might take a lot longer than that but I thought I'd check
it's status (via a flag) every 10 seconds or so. That would make the user
think something is happening.

I used a lot of your code but instead of the shutdown function and a call
to header(), I put a META refresh tag in the header and called the Oracle
stored procedure at the end of the script. So 2 seconds after the script
completes, the page is redirected to another page that shows the results.

The main problem with my approach is that it is subject to all the failings
of the flush() function -- which can't *force* a server (much less the
browser) to flush output. But, well, close enough for gub'ment work. It
works on the servers & browsers we're using today. The worst that can
happen is that the user doesn't get the "Please wait" message. He might
think his browser is hung but by the time he looks up my phone number it
will have finished.

<HTML>
<HEAD>
<META http-equiv=Refresh CONTENT="2; URL=billing.php">
</HEAD>
<BODY>

Please wait...

<?php
flush();
set_time_limit(0);
ignore_user_abort(1);

$stmt = OCIParse ($dbh, "BEGIN DOSOMETHING(); END;");
OCIExecute ($stmt, OCI_COMMIT_ON_SUCCESS);
?>

Finished! This page will refresh in 2 seconds!
</BODY>
</HTML>



Relevant Pages

  • Re: Choosing whitch button will act as submit button
    ... Use the script exactly as supplied for the browser. ... server-code cannot decide whitch button should be the submit button. ... one server side form tag, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Response.Flush: Differences between IIS 6.0 and 5.0?
    ... Here's an ASP ... 'See how long it takes to Flush to the browser ... Browsing to this ASP page hosted on an IIS 5.0 server yield the following ...
    (microsoft.public.inetserver.iis)
  • Re: different behavior - localserver vs prod server
    ... But I don't understand what you mean when you say to type the src urls ... into the browser to see if they are correct. ... > Smart Navigation and Client Range checking are implemented by client script, ... and how it behaves on the server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using anchor links within pages defined by GETS
    ... So the content in the browser ... sure the submitted value for pid is valid and not a NULL or SQL ... What URL is sent to the server? ... because your script should never see the ...
    (comp.lang.php)
  • Re: Is script type="text/perl" OK?
    ... :} I've asked this on a html forum but I'll ask it here also. ... Well, as long as your browser is able to execute the script, sure. ... Since the server is doing the running of the ...
    (comp.lang.perl.misc)