Date:  02/22/2013 02:29:37 PM Msg ID:  004583
From:  FoxWeb Support Thread:  004569
Subject:  Re: Progress Bar Conundrum
I checked the output of test.fwx from your server and it is being received in chunks as expected. However, browsers do not seem to be rendering it so, waiting for the whole content to be received.
 
After some research and experimentation I found that different browsers cache content internally. It seems that this buffer is fairly small, because if you send larger chunks of content it does get rendered. For example, if you modify test.fwx to send 100 spaces after each number, like below, it all works fine:
 
 response.write(str(i) + space(100) + CRLF)
 
You could do the exact same thing with the progress bar updates. 
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/22/2013 02:13:27 AM:
Well, I've got egg on my face. I misspelled the file name. I entered test.fwx into the string but named the file text.fwx. Pretty stupid....Sorry.
 
Here is the output but I'm not sure how to decipher it.
 
C:\>"\program files\GnuWin32\bin\wget.exe" -O- http://www.x-laser.net/test.fwx
 
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\program files\GnuWin32/etc/wgetrc
--2013-02-22 02:06:26--  http://www.x-laser.net/test.fwx
Resolving www.x-laser.net... 207.145.111.195
Connecting to www.x-laser.net|207.145.111.195|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `STDOUT'

    [<=>                                    ] 0           --.-K/s

<!DOCTYPE html>
<html>
<head><title>Buffer Test</title>
</head>
<body>
         1
         2
    [ <=>                                   ] 97           124B/s
        3
    [  <=>                                  ] 109         81.1B/s
        4
    [   <=>                                 ] 121         53.1B/s
        5
    [    <=>                                ] 133         46.8B/s
        6
    [     <=>                               ] 145         38.4B/s
        7
    [      <=>                              ] 157         36.2B/s
        8
    [       <=>                             ] 169         32.0B/s
</body>
    [         <=>                           ] 187         32.1B/s   in 5.8s

2013-02-22 02:06:32 (32.1 B/s) - `-' saved [187]

C:\>


Thanks for your help and sorry for being stupid -- late night programming.

 Joe

 
 
 
 
 
Sent by FoxWeb Support on 02/22/2013 12:20:09 AM:
 The URL in the wget command line was just an example. You will need to modify it, so that it references the script that you created with the code I provided a few messages back (see below). 
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/21/2013 11:03:15 PM:
I ran the application twice, once with test.fwx in /admin/ and once in the x-laser.net/ root. Each time the application reported it could not find the file. I consulted the docs and could not find anything done wrong. Here is the output.
 
C:\>"\Program Files\GnuWin32\bin\wget.exe" -O- http://www.x-laser.net/test.fwx
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files\GnuWin32/etc/wgetrc
--2013-02-21 22:51:53--  http://www.x-laser.net/test.fwx
Resolving www.x-laser.net... 207.145.111.195
Connecting to www.x-laser.net|207.145.111.195|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `STDOUT'
    [<=>                                    ] 0           --.-K/s
<!-- ">" --></p>
<table border=0 cellpadding=1 cellspacing=0 width=100%>
<tr>
<td colspan=3><hr><b>There was an error during the interpretation of your reques
t.</b><br><br></td>
</tr>
<tr>
<td nowrap><small><b>Message:</b></small></td>
<td></td>
<td><small>Script "TEST.FWX" is invalid, or non-existent</small></td>
</tr>
<tr>
<td colspan=3><hr></td>
</tr>
</table>
    [ <=>                                   ] 369         --.-K/s   in 0s

2013-02-21 22:51:53 (51.0 MB/s) - `-' saved [369]
C:\>

BTW, IIS6 does have buffering on.


Any thoughts?

Thanks for your help.

 
Sent by FoxWeb Support on 02/21/2013 02:50:26 PM:
There are two reasons why the progress bar is not working:
  • The web server is buffering content until the end of the request and then sends all of it at the same time.
  • The web browser is receiving the content in installments, as intended, but for some reason is not responding to the JavaScript commands appropriately.
 The test code I sent you yesterday was intended to test the above, but it's hard to do with a browser.
 
You may want to install wget (latest installer can be found here) to see in real time what is being received from the web server. Once you have installed wget, run the following command in a windows command prompt:
 
"\Program Files (x86)\GnuWin32\bin\wget.exe" -O- http://www.x-laser.net/admin/test.fwx
 
You will need to adjust the path to wget.exe and also the URL to the test script. The -O- switch instructs wget to display output to the console window. Is all the content arriving at once at the end of the request, or in batches every half second?
 
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/21/2013 12:53:24 PM:
I removed the content type line and ran it again -- no change.  I am using windows server 2003 SP 2 and IIS. All patches have been installed.
 
When I put the code block just above request.formcount I get a small one column two row unpopulated box with thick gray borders. Once I hit the submit button the XML code processes for about 5-7 seconds then the box disappears when the results are posted to the screen. Here is the code block.
 
First attempt seeing only the small unpopulated box.
<%
    response.buffer = .F.
    response.write("<div id='progressOuterDiv'></div>")
    response.write("<script language='JavaScript'>")
    response.write("var progressBar = new cProgressBar();")
    response.write("progressBar.init();")
    response.write("progressBar.show(true);")
    response.write("</script>")
%>
 
<%
if request.formcount("Submit") > 0
 
    for x = 1 to m.RowTotal
 
       response.write("<script language='JavaScript'>progressBar.show(false);</script>")
       response.flush
 
        XML post
        XML get response
        Send results to screen
 
     end for
 
     response.write("<script language='JavaScript'>progressBar.show(false);</script>")
     response.flush
 endif
%>
 

 
Second attempt without seeing the unpopulated box.
<%
if request.formcount("Submit") > 0
    response.buffer = .F.
    response.write("<div id='progressOuterDiv'></div>")
    response.write("<script language='JavaScript'>")
    response.write("var progressBar = new cProgressBar();")
    response.write("progressBar.init();")
    response.write("progressBar.show(true);")
    response.write("</script>")
 
    for x = 1 to m.RowTotal
 
       response.write("<script language='JavaScript'>progressBar.show(false);</script>")
       response.flush
 
        XML post
        XML get response
        Send results to screen
 
     end for
 
     response.write("<script language='JavaScript'>progressBar.show(false);</script>")
     response.flush
 endif
%>
 
I have actually put the progress bar block in various places and portioned it out in various places without luck.   
 
Don't we all love programming?
 
Joe
 
 
Sent by FoxWeb Support on 02/21/2013 02:05:59 AM:
Which Windows version and which web server are you running?
 
Try removing the content type line at the top of the script. Does it make a difference? 
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/21/2013 12:19:17 AM:
Well, it's just plain bad luck I guess. I copied everything in the code block into a new file and saved it and ran it. Sadly, all 8 iterations printed at the same time once the page loaded. Thinking my workstation was infested, I tried running the same script in three browsers on four different workstations, PC and Mac. Each had the same result. I am thinking now it's something on the server.
 
Which "incomplete web services code" was removed?
 
Joe
 
Sent by FoxWeb Support on 02/20/2013 05:03:49 PM:
The script you provided to us in your email worked fine once we removed the incomplete web services code. I don't know why it's not working on your own server.
 
Please try the following script. It should display the numbers 1 through 8, in half second intervals (as opposed to displaying all the numbers at once after 4 seconds).
 
 

<%Response.ContentType = 'text/html;charset=utf-8'%>

<!DOCTYPE html>

<html>

<head><title>Buffer Test</title>

</head>

<body>

<%

response.buffer = .F.

for i = 1 to 8

response.write(str(i) + CRLF)

response.flush

wait '' timeout .5

next

%>

</body>

</html> 


The Response.ContentType call is required.

 

FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/19/2013 11:10:37 PM:
Thanks for the response. Here is a link to the live test script in question. I have run this script in FireFox, Chrome, and Safari each with the same results. Again, I only want the progress bar to show after the form is submitted going to the request.formcount line in the same script and between the for-next loop.
 
 
Thanks for any comments.
 
Joe 
 
Sent by FoxWeb Support on 02/19/2013 07:03:36 PM:
It would be helpful if you provided a runnable sample program, illustrating the problem. You should replace database and web services operations with simple pause calls (WAIT WINDOW "" TIMEOUT x).
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/19/2013 04:21:27 PM:
Sorry, that's just pseudocode  to show I had used <link> and <script> to bring in the css and js code. I tried to reduce the amount of general script for brevity opting to focus on more important code from the progressbar example.
 
Joe
 
Sent by FoxWeb Support on 02/19/2013 02:40:45 PM:
I don't understand what the "import" statements are doing in your HTML HEAD section. You need to place the css and js files in your web tree and reference them with <link> and <script> elements, respectively (or incorporate them in your output after reading their contents with FILETOSTR, like in ProgressBarDemo.fwx).
 
Also, I don't see a BODY element in your HTML. It is recommended that you validate your HTML and JS code with one of the many available validators.
FoxWeb Support Team
support@foxweb.com email
Sent by Joe Goldsmiith on 02/17/2013 10:17:15 PM:
 I incorporated the FoxWeb progress bar into a slow running script that fetches FedEx XML rates. The script runs slowly because FedEx requires a separate call for each service. So far I have 7 services requiring a call each. All the programming is on one page (fedex.fwx) with a form on top with action="fedex.fwx" to re-call the page. Once the script gets to Request.FormCount lower down the page, the progress bar code needs to run but it doesn't until the script reaches the bottom of the page. Needless to say, this is not the intended behavior.
 
What I need to know is how to have code below FormCount execute and show to screen while the loop for each service runs. I understand that how it would work for whole page loading but wish to start and stop it below Request.FormCount and within a loop. Here is some sample code for consideration.
 
*** Script File FedEx.fwx
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
import progress.css
import progress.js
 </head>
<head>
<FORM METHOD="post" ACTION="FedEx.fwx" name="FedExRateFetch">
     Get information to calculate rate...
 </form>
 
<%
 IF Request.FormCount("Submit") > 0
    ***PROGRSS BAR
    M.StartTime = SECONDS()
    response.write("<div id='progressOuterDiv'></div>")
    ***Initialize and show the toolbar
    response.write("<script language='JavaScript'>")
    response.write("var progressBar = new cProgressBar();")
    response.write("progressBar.init();")
    response.write("progressBar.show(true);")
    response.write("</script>")
    
    for x = 1 to m.nRowTotal
        M.TotalSteps = m.nRowTotal

       XML To Send FedEx Rate Request...
       
        XML Fetch Rate Response
 
        Send Rates To Screen
 
        response.write("<script language='JavaScript'>UpdateProgressBar(x / M.TotalSteps * 100, 'Completed step ' + Server.ToString(x) + ' of ' + Server.ToString(M.TotalSteps))</script>")
        WAIT '' TIMEOUT .5
 
      endfor   && loop through all services
 
endif
%>
<!-- Now hide the toolbar -->
<script language="JavaScript">progressBar.show(false);</script>
</body>
</html>
 
<%
**************************************************************************************************
PROCEDURE UpdateProgressBar
* Generates JavaScript code, which calls progressBar.update() method to update
* the progress bar, for example:
* <script language="JavaScript">progressBar.update(47, 'Completed 47% of the process');</script>
**************************************************************************************************
    LPARAMETERS PercentComplete, StatusText
    * First of all extend the script timeout by 10 seconds if it will expire in less than 5 seconds
    IF (SECONDS() - StartTime) + 5 >= Server.ScriptTimeout
        Server.AddScriptTimeout(10)
    ENDIF
    IF TYPE('M.StatusText') <> 'C'
        * No status text was specified -- Let ProgressBar code generate the status text
        Response.Write([<script language="JavaScript">progressBar.update(] + Server.ToString(M.PercentComplete) + [);</script>] + CRLF)
    ELSE
        Response.Write([<script language="JavaScript">progressBar.update(] + Server.ToString(M.PercentComplete) + [, '] + M.StatusText + [');</script>] + CRLF)
    ENDIF
    * Force output to be sent to browser
    Response.Flush
ENDPROC
%>
 
Any thoughts from anyone as to how to make the progress bar show up after Request.FormCount and update within the For Next loop?
 
Thanks much!!!
 
Joe