473,800 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4328
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_abo rt(1);
register_shutdo wn_function("fo o");
header("locatio n: 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_abo rt(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******@nospa m.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
automaticall y 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($handl e) : 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($st mt, OCI_DEFAULT), $stmt);
check_oci_error (OCICommit($con n));

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

<pre>
<?php
function check_oci_error ($status, $handle = null) {
if (!$status) {
$error = $handle ? OCIError($handl e) : 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($st mt, 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='waitforjo b.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***@electric toolbox.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_abo rt(1);
register_shutdo wn_function("fo o");
header("locatio n: 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_abo rt(1);

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

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

Jul 17 '05 #4
JGH wrote:
Chris Hope <ch***@electric toolbox.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_abo rt(1);
register_shutdo wn_function("fo o");
header("locatio n: 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_abo rt(1);

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

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
1116
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 the UIPManager to start the appropriate task which redirects the user to the appropriate page. The starting page then has a query string which includes "CurrentTask=<enter GUID here>". This causes problems if the user saves the URL to their...
9
4653
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
4146
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. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
7
2921
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 database into classes, which are used throughout the application. I have made class collections which, upon reading from the DB, create an instance of the class and store the DB values in there temporarily. My problem is that if user1 looks at...
24
1922
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 deployment my app is 427KB (even with modem dialup speed it doesn't take long to download) -- the user gets a very friendly secure WindowsForm app (most of them don't even notice they're not under IE anymore) that performs considerably faster than...
5
1081
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 user needs to see as they are being made. However, it is desirable that the user is not able to actually interact with the application as far as clicking buttons, etc, goes. Application.DoEvents seems to update the UI nicely, but the user can...
8
3192
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 I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class ProjectDetailsControl<TEntryServiceProvider: UserControl, INamingContainer where TEntryServiceProvider : IEntryServiceProvider...
4
2598
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 have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with.
1
2491
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 a page that connects to a webservice to show the user the progress of this operation. It seems almost a given that I must use either ajax or some kind of control to do this. Any suggestions would be greatly appreciated. So far I have come up...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.