473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

JGH
I want to create a web page that allows a user to run an oracle stored
procedure. That's easy enough but the problem is that the procedure
might take several seconds to complete.

I don't want the user to be able to cancel the process. So,
essentially, I want to call the procedure as a background task and have
the web page that the user sees display something like, "Please wait
while I update the database." And then every 10 seconds or so
automatically refresh the page.

So the tricky part, as far as I can tell, is to get it to NOT wait
while the stored procedure is executing.

<?php
$stmt = OCIparse ("BEGIN UPDATEDATABASE(); END;");
OCIexecute ($stmt);
?>

But this just sits there while the procedure executes.

Jul 17 '05 #1
4 4308
JGH wrote:
I want to create a web page that allows a user to run an oracle stored
procedure. That's easy enough but the problem is that the procedure
might take several seconds to complete.

I don't want the user to be able to cancel the process. So,
essentially, I want to call the procedure as a background task and have
the web page that the user sees display something like, "Please wait
while I update the database." And then every 10 seconds or so
automatically refresh the page.

So the tricky part, as far as I can tell, is to get it to NOT wait
while the stored procedure is executing.

<?php
$stmt = OCIparse ("BEGIN UPDATEDATABASE(); END;");
OCIexecute ($stmt);
?>

But this just sits there while the procedure executes.


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 process.
You may just want to make them wait it out but use ignore_user_abort(1) to
ensure they can't stop the page from doing its magic.

http://www.php.net/set_time_limit
http://www.php.net/ignore_user_abort
http://www.php.net/register_shutdown_function
http://www.php.net/header

--
Chris Hope
The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
On Thu, 6 May 2004 22:00:24 +0000 (UTC), JGH <jo******@nospam.tds.net> wrote:
I want to create a web page that allows a user to run an oracle stored
procedure. That's easy enough but the problem is that the procedure
might take several seconds to complete.

I don't want the user to be able to cancel the process. So,
essentially, I want to call the procedure as a background task and have
the web page that the user sees display something like, "Please wait
while I update the database." And then every 10 seconds or so
automatically refresh the page.

So the tricky part, as far as I can tell, is to get it to NOT wait
while the stored procedure is executing.

<?php
$stmt = OCIparse ("BEGIN UPDATEDATABASE(); END;");
OCIexecute ($stmt);
?>

But this just sits there while the procedure executes.


One option would be to submit a job using DBMS_JOB, set to run once
immediately, and have it set some flag that you can query for in the subsequent
refreshes, or query USER_JOBS with the job ID. Something like:

async.php:
----------

<pre>
<?php
function check_oci_error($status, $handle = null) {
if (!$status) {
$error = $handle ? OCIError($handle) : OCIError();
die("error: " . $error['message']);
}
}

check_oci_error($conn = OCILogon('test', 'test', 'dev101'));
check_oci_error($stmt = OCIParse($conn, "
begin
dbms_job.submit(:job_id,
'begin dbms_lock.sleep(25); end;',
sysdate);
end;"), $conn);

OCIBindByName($stmt, ':job_id', &$job_id, 38);

check_oci_error(OCIExecute($stmt, OCI_DEFAULT), $stmt);
check_oci_error(OCICommit($conn));

echo "<a href='waitforjob.php?job_id=$job_id'>Wait for job $job_id</a>";
?>
</pre>
waitforjob.php:
---------------

<pre>
<?php
function check_oci_error($status, $handle = null) {
if (!$status) {
$error = $handle ? OCIError($handle) : OCIError();
die("error: " . $error['message']);
}
}

check_oci_error($conn = OCILogon('test', 'test', 'dev101'));
check_oci_error($stmt = OCIParse($conn, 'select broken from user_jobs where job
= :job_id'));

OCIBindByName($stmt, ':job_id', $_GET['job_id'], -1);

check_oci_error(OCIExecute($stmt, OCI_DEFAULT), $stmt);

if (OCIFetchInto($stmt, $row, OCI_ASSOC)) {
var_dump($row);
if ($row['BROKEN'] == 'Y') {
echo "Job broken.";
} else {
echo "Job still running. (<a
href='waitforjob.php?job_id={$_GET['job_id']}>refresh</a>)";
}
} else {
echo "Job complete.";
echo "<a href='async.php'>submit another</a>";
}
?>
</pre>

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3
JGH
Chris Hope <ch***@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>

Jul 17 '05 #4
JGH wrote:
Chris Hope <ch***@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>


You probably need to add another flush() after the last closing HTML tag to
ensure it really is flushed. Although as you pointed out flush() doesn't
always do what you expect. In my actual code I also had a call to
ob_end_flush() directly under the flush() call. It was a long time ago I
coded it so I guess that must have been after experimentation.

--
Chris Hope
The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alan Wedin | last post by:
I have installed the Microsoft "User Interface Process Application Block". My application work fine as long as the user starts at the home page which doesn't inherit WebFormView. This page uses...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
24
by: Rob R. Ainscough | last post by:
VS 2005 I have: ClickOnce deployment User's that hate and or don't want to use an IE Client (don't blame them) I don't see how ASPX web pages are going to survive? With .NET 2.0 and clickonce...
5
by: Marina | last post by:
What is the right way to go about making sure an application is not frozen and unresponsive while a relatively long running process is going on? The process is making updates to the UI, which the...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
4
by: dumbkiwi | last post by:
I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I...
1
by: Ralph | last post by:
Okay I have a website where the user is going to hit a button to kick off a process that is going to take a long amount of time. Is there anyway without using AJAX, or possibly a windows control on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.