Re: A progress page with PHP + PostgreSQL - Mailing list pgsql-php

From Jona
Subject Re: A progress page with PHP + PostgreSQL
Date
Msg-id FJEOLDMFKOBPOLOACKHHAEBPCBAA.jonanews@orioninformationservices.com
Whole thread Raw
In response to Re: A progress page with PHP + PostgreSQL  ("Thom Dyson" <TDyson@sybex.com>)
List pgsql-php
What you could do is utilize the php flush() function while your script is
looping
Please note however that although this function clears the internal output
buffer in PHP, it doesn't affect the output buffer in your webserver (if
such is used), neither does it prevent the user's browser from caching in
its input buffer (most browsers have an input buffer on 256 bytes)

There's a work around to the browser input however, something like the
following should do the trick if used as step 2) and 3) as it does both the
work and displays the progress bar.

<?php
// Connect to database
$rDBconn = pg_connect("user=XX pass=YY");

// Get lots and lots of data
$strSQL = "SELECT * FROM Huge_Tbl";
// Execute query
$res = pg_query($rDBconn, $strSQL);

// headline
$sOut = "<strong>Progress</strong>" . "<br />";
// Append blank spaces to fill browsers input buffer
$sOut = $sOut . str_repeat(" ", 260 - strlen($sOut) );
// Display headline
echo $sOut;
// Flush PHP output buffer
flush();

// Loop through recordset
while($RS = pg_fetch_array($res) )
{
    /*
        Do your calculations with the current record
    */
    // Progress bar
    $sOut = "# ";
    // Append blank spaces to fill browsers input buffer
    $sOut = $sOut . str_repeat(" ", 260 - strlen($sOut) );
    // Display next
    echo $sOut;
    // Flush PHP output buffer
    flush();
}
?>

Of course this will only work if you return your recordset in chunks to PHP,
should you however utilize a PostGre function to do some heavy calculations
(and thus having all your work in the database) PHP making a progressbar is
a bit more tricky.
In this exampla you might want to consider counting the number of records
first so you can give the user an idea of how long
the progress actually is instead of simply showing progress.

Hope this helps

/Jona

-----Original Message-----
From: pgsql-php-owner@postgresql.org
[mailto:pgsql-php-owner@postgresql.org]On Behalf Of Thom Dyson
Sent: 15 December 2003 21:23
To: pgsql-php@postgresql.org
Subject: Re: [PHP] A progress page with PHP + PostgreSQL



I've never done this, but my first guess would be to send the user to a
temp page after step 1.  This temp page would have some animated gif so the
user thinks something is happening (step 3).  After a fixed time period
(equal to the loop time on the gif), the temp page auto-redirects to a new
page that shows the final results (step 4)

Thom Dyson
Director of Information Services
Sybex, Inc.

On 12/15/2003 11:30:06 AM, Sai Hertz And Control Systems
<sank89@sancharnet.in> wrote:
> Dear all,
>
> Permit me to gain some of your most valuable knowledge ...........
>
> In one of our application a process takes  time and as the work is in
> progress we want to show our customer a progress bar
> or processing page
> It is some thing like this
>
> 1. Customer Clicks on button EXECUTE
> 2. The pgsql  function is invoked
> Now normally after step 2  a  success page will return only after the
> postgresql function finishes
> but we would like as
> 3. Show progress of executed function
> 4. On Sucessfull completion Show  Success page
> else error page
>
> Would be  greatefull to all  for  any tiny clue.
>
>
> Regards,
> Vishal Kashyap
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


pgsql-php by date:

Previous
From: Noel
Date:
Subject: Re: Cancel a query when user leaves a web page
Next
From: "David Cruz Ramos"
Date:
Subject: unsubscribe pgsql-php