Gossamer Forum
Home : General : Perl Programming :

Server push continued...

Quote Reply
Server push continued...
Thanks Alex for the answer to my previous post. And now the by now customary follow-up questions... Smile

1) Can you run an NPH script as a required library? i.e. Say I only needed to use NPH if something was selected in the form, can I use:

if ($option == 1) {
require "nph-encrypt.pl";
&encrypt;
}

I'm doubtful...

2) I have an NPH script working, but what I would ultimately like to do is push the "Processing..." message to the screen, and then when processing is done, send them off to a results page, using some of the data from the process. Again, because this is an encryption routine, I don't want to use GET, so META refresh is out of the question. I perused the Perl docs and came across PUSH, but can I intergrate that with CGI? Here's the subroutine:

Code:
sub process {
use CGI;
CGI->nph(1);
$|++;
print CGI->header();
print "Encrypting...<br><br>";
&encrypt;
print "Encryption complete.<br><br>";
print "Sending mail...<br><br>";
&sendmail;
print "Mail sent.<br><br>";
print "All done. Test successful.";
}

So after the last print statement I would like to clear the screen and push a new page to the browser. Any ideas?

And 3) As an aside, I'm not sure if I have the PUSH module, so what's the story with installing Perl modules? Do you have to be running as root to install them? I'm not brilliant with modules and up until now I've avoided them (still quite happy with my modified version of cgi-lib.pl!). I realise that as I get more experienced they'll become indispensible, but for now I'd like to work away as I am. That said, the stuff I want to do requires modules more and more, so the time has come... Smile

Thanks,
adam
Quote Reply
Re: Server push continued... In reply to
Thanks anyway Alex, I guess I'll just have to "suck it and see". After having a wee poke around my server I found that my host has a fairly large complement of libraries and modules, including PUSH, so I'll have a go.

If anyone else has any advice though, I can point you to an example of exactly what I'm looking for -- the Metacrawler -- www.metacrawler.com search routine is bang on, it pushes the number of hits to the screen, and then when it's done, sends the user off to a new page. Only problem is, the new page is called via GET, which is useless to me... Smile

Thanks,
adam

[This message has been edited by dahamsta (edited May 27, 1999).]
Quote Reply
Re: Server push continued... In reply to
 
Quote:
Can you run an NPH script as a required library?

No. The reason is Apache will buffer output unless the name of the script that was run starts with nph-. Apache doesn't know about the internals of the perl script, it only knows about the name of the called script.

As for the others, I've never played with PUSH, so I'm not sure I can be much help. I also only thought it worked with Netscape, but could be mistaken..

Cheers,

Alex
Quote Reply
Re: Server push continued... In reply to
Just curious, why can't you use the GET method? Too much data?

Alex
Quote Reply
Re: Server push continued... In reply to
Well, I wanted to avoid using GET and keep everything self-contained, but that seems impossible because I've already sent a Content-type header to the browser, so I can't push a new page to it (or can I?). And, if I use PUSH, I'm not sure all browsers will handle it, plus it'll clear the page every time, I only want it to clear it when the encryption is done and the mail is sent. Fussy aren't I? Smile

The aim of this is to send encrypted (using PGP) output back to the user to show them what was sent in a mail message. I guess it's not necessary, this is really only experimentation, but it would be nice to figure out. Anyway, I tried it this way:

Code:
use CGI;
CGI->nph(1);
$|++;
print CGI->header();
print "Encrypting...<br><br>";
&encrypt;
print "Encryption complete.<br><br>";
print "Sending mail...<br><br>";
&sendmail;
print "Mail sent.<br><br>";
print "All done. Test successful.";
print "<meta http-equiv=\"refresh\" content=\"0; url=confirm.cgi?sentto=$tomail&message=$encrypted\">";

The refresh tag sends the output off in the query string to another simple script which parses it and should deliver the output back to the browser. The problem with this is that the $encrypted variable returned from PGP contains line breaks, so I'm getting an error back from the server. Funny thing is, it's a 404. I don't know if that's right,but I guess the line breaks might have that effect.

The only thing I can think of is to convert the line breaks to something else before I send the string off in the query and reconvert them in the confirm script, but then what if the encrypted message contains the "something else"?

Also, I'm worried that if the message is a long one, the query string will be very long and send the user an error. What are the limits?

Thanks again for you help Alex,
adam