Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > need help, will pay

Reply
Thread Tools

need help, will pay

 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      09-02-2009
boman <(E-Mail Removed)> wrote:
> On Sep 2, 2:23*pm, Nathan Keel <(E-Mail Removed)> wrote:
> > I see, well then you might need to get someone to take a look or give
> > you different options. *There are some things you can try, but if
> > you've set the buffering in the script, then the problem does lie
> > elsewhere. *You also might consider something like a server-push
> > solution or just saying "click here to view the results", which can
> > then open a file or read in the data as its happening (perhaps not via
> > a CGI script).


> The link idea could be a fall back, but I'd like to automate that. I
> would think you can do that by setting the refresh parameter in
> cgi:m's header call, but I cannot figure out how to get the refresh
> to exit once the process is complete, it just refreshes and refreshes
> and refreshes, even when the process completes.


That should be simple, just don't send the meta refresh anymore
with the last page when the program is done.

The real problem is more that this can't be done with a simple
CGI script because when the browser (re-)loads the page the
web server will start a new CGI script that doesn't know any-
thing about what happened before. So you will probably need
some background process that waits for requests from the CGI
script and then passes back the newly calculated data back to
it (which the CGI script then sends on to the web server that
transmits them to the browser).

Since there could be several browsers asking simultaneously
for new pages you also would have to be able to handle cal-
culations in parallel within that background process. And
you would have to rely on some mechanism, e.g. cookies, to
know which results are for which client.

Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
 
boman
Guest
Posts: n/a
 
      09-02-2009
Here's the code so far. It continues to update the browser, although
it's sloppy, and when the process is done, it does display the "done"
page. But then it refreshes again in 5 seconds.



#!c:/Perl/bin/perl.exe

use CGI qw/:standard/;
use Win32:rocess;
use Win32:rocess qw/STILL_ACTIVE/;
use Win32;

$| = 1;

Win32:rocess::Create($MainProcessObj,
"c:\\WINDOWS\\System32\\netstat.exe",
"netstat",
0,
NORMAL_PRIORITY_CLASS,
".");
$MainProcessObj->GetExitCode($exitcode);

$counter = 0;
while ($exitcode != 1) {
if ($exitcode == 0) {
print header, start_html,h4("something is wrong"), end_html;
exit;
} else {
print header(-Refresh=>"5"), start_html;
print p("waiting, $counter secs... $exitcode "), end_html;
$counter = $counter + 5;
sleep 5;
$MainProcessObj->GetExitCode($exitcode);
}
}

if ($exitcode = "") {
print header, start_html, p("done $exitcode"), end_html;
}
 
Reply With Quote
 
 
 
 
Nathan Keel
Guest
Posts: n/a
 
      09-02-2009
boman wrote:

> Here's the code so far. It continues to update the browser, although
> it's sloppy, and when the process is done, it does display the "done"
> page. But then it refreshes again in 5 seconds.
>


If you're happy with the result as it is and just don't want it to
refresh, just pass a variable to the script that let's the script know
that it's been refreshed (once) already and doesn't put in the refresh
header in that resulting document's (web page) output.

 
Reply With Quote
 
Ron Bergin
Guest
Posts: n/a
 
      09-02-2009
On Sep 2, 12:26*pm, boman <(E-Mail Removed)> wrote:
> Here's the code so far. It continues to update the browser, although
> it's sloppy, and when the process is done, it does display the "done"
> page. But then it refreshes again in 5 seconds.
>
> #!c:/Perl/bin/perl.exe
>
> use CGI qw/:standard/;
> use Win32:rocess;
> use Win32:rocess qw/STILL_ACTIVE/;
> use Win32;
>
> $| = 1;
>
> Win32:rocess::Create($MainProcessObj,
> * * * * "c:\\WINDOWS\\System32\\netstat.exe",
> * * * * "netstat",
> * * * * 0,
> * * * * NORMAL_PRIORITY_CLASS,
> * * * * ".");
> $MainProcessObj->GetExitCode($exitcode);
>
> $counter = 0;
> while ($exitcode != 1) {
> * * * * if ($exitcode == 0) {
> * * * * * * * * print header, start_html,h4("something iswrong"), end_html;
> * * * * * * * * exit;
> * * * * } else {
> * * * * print header(-Refresh=>"5"), start_html;
> * * * * print p("waiting, $counter secs... $exitcode "), end_html;
> * * * * $counter = $counter + 5;
> * * * * sleep 5;
> * * * * $MainProcessObj->GetExitCode($exitcode);
> * * * * }
>
> }
>
> if ($exitcode = "") {
> * * * * print header, start_html, p("done $exitcode"), end_html;
>
> }
>
>


Sloppy is an understatement.

Why are you printing/reprinting the html header in a loop and why the
'sleep'?

You should execute that script outside of the cgi environment and
remove the 'sleep' line to see why that's the wrong thing to do.

Rather than using Win32:rocess, I think it would be better to use
Net::Netstat::Wrapper.

http://search.cpan.org/~mcantoni/Net...tat/Wrapper.pm
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      09-02-2009
On Wed, 02 Sep 2009 10:06:08 -0700, boman wrote:

> Yes, I've got the $|=1 set, and I made sure apache is not buffering
> output, but can't get around the browsers doing the buffering (I think
> this is what's happening).


Some (all?) versions of IE need 256 spaces first as start of the body.
It's weird, but true. If your problem occurs in other browsers as well,
this is not the solution, if your problem is only in IE, give it a try.

HTH,
M4
 
Reply With Quote
 
Ron Bergin
Guest
Posts: n/a
 
      09-02-2009
On Sep 2, 10:06*am, boman <(E-Mail Removed)> wrote:
>
> Yes, I've got the $|=1 set, and I made sure apache is not buffering
> output, but can't get around the browsers doing the buffering (I think
> this is what's happening).
>


If you run the script from the command line, you'll see that the issue
not that the browser is buffering the netstat output, the netstat
command is buffering its output.
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      09-04-2009
On 2009-09-02 19:09, Jens Thoms Toerring <(E-Mail Removed)> wrote:
> boman <(E-Mail Removed)> wrote:
>> On Sep 2, 2:23*pm, Nathan Keel <(E-Mail Removed)> wrote:
>> > I see, well then you might need to get someone to take a look or give
>> > you different options. *There are some things you can try, but if
>> > you've set the buffering in the script, then the problem does lie
>> > elsewhere. *You also might consider something like a server-push
>> > solution or just saying "click here to view the results", which can
>> > then open a file or read in the data as its happening (perhaps not via
>> > a CGI script).

>
>> The link idea could be a fall back, but I'd like to automate that. I
>> would think you can do that by setting the refresh parameter in
>> cgi:m's header call, but I cannot figure out how to get the refresh
>> to exit once the process is complete, it just refreshes and refreshes
>> and refreshes, even when the process completes.

>
> That should be simple, just don't send the meta refresh anymore
> with the last page when the program is done.
>
> The real problem is more that this can't be done with a simple
> CGI script because when the browser (re-)loads the page the
> web server will start a new CGI script that doesn't know any-
> thing about what happened before.


I think you haven't read the "stonehenge article" mentioned by boman.
Here it is: http://www.stonehenge.com/merlyn/LinuxMag/col39.html

> So you will probably need some background process that waits for
> requests from the CGI script and then passes back the newly calculated
> data back to it (which the CGI script then sends on to the web server
> that transmits them to the browser).


No, the idea is to have a long-running process just write information to
a file. The CGI script then just has to look at the file to determine
what it should send back to the client.

>
> Since there could be several browsers asking simultaneously
> for new pages you also would have to be able to handle cal-
> culations in parallel within that background process.


Just use several background processes.

> And you would have to rely on some mechanism, e.g. cookies, to know
> which results are for which client.


Query parameters are more reliable for that.

hp
 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      09-05-2009
Peter J. Holzer <(E-Mail Removed)> wrote:
> I think you haven't read the "stonehenge article" mentioned by boman.
> Here it is: http://www.stonehenge.com/merlyn/LinuxMag/col39.html


No, I hadn't since I could find it. Thanks for the link.

Regards, Jens
--
\ Jens Thoms Toerring ___ (E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wal-Mart's movie download plan: pay and pay again Modemac DVD Video 23 12-08-2006 02:40 PM
The battle moves on from why pay for an OS to why pay for an application(database) thing2 NZ Computing 40 02-18-2006 10:35 PM
need help, will pay Michael Williams Cisco 2 04-29-2005 06:24 PM
Need a few lines of code help, will pay! Robert Johnson ASP .Net 3 08-04-2003 06:06 PM



Advertisments