Solved

Server Proccessing

Posted on 1998-11-26
17
180 Views
Last Modified: 2010-03-04
I have a Perl script that recieves an HTML form input and sends mail.
The problem is that it takes very long time for the Perl script to open a session with the SMTP server. The SMTP server is very slow, so there is nothing to do about that.
Anyway, can I print the output HTML from the script to the client, and the server will wait to open an SMTP session?
I mean, print the "Thank you" reply to the client and the mail send will process on the server, thus the client shouldn't have to wait so long...

Hope for a good one this time.
Thanks.
0
Comment
Question by:faur
  • 6
  • 6
  • 4
  • +1
17 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1206630
Can you fork off a separate process to open the SMTP session?
0
 

Author Comment

by:faur
ID: 1206631
I don't know what you mean...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206632
if (fork) {
   print "Thank you\n";
} else {
   # do your SMTP things
   exit 0;
}
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:faur
ID: 1206633
Could you explain me what these lines do?
I'm quite new to perl.
Do I need to write this code exactly as you write it?

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206634
This program forks, the child and parent part are processed  (somehow) simultaneously.
The child part should do the SMTP session,
while the parent just continues and prints zour "Thank you".
Yes you type the lines as is. Of cause you have to add you special code in the child and parent part.
AFAIK, this will not work for any kind of M$ based systems :-( except XENIX:)
0
 

Author Comment

by:faur
ID: 1206635
Maybe I wrote it wrong, but it didn't worked for me...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206636
would be nice to see some code or error messages ;-)
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206637
I agree with ahoffman.  If I could figure this out from here, I'd work for 1-800-PSYCHIC :)
0
 

Author Comment

by:faur
ID: 1206638
Ok, guys, cool down there :) here's the lame code:

------------------------------
#!/usr/local/bin/perl

use Net::SMTP;
require "cgi-lib.pl";

&ReadParse(*input);

if (fork) {
    # The "Thank You" screen
    &thanx;
    } else {
        # SMTP stuff
        &send_mail;
        exit 0;
        }
------------------------------

I'm recieving an error on the "if (fork) {" line...
I hope that helps...
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206639
Again, what is the error?  Of course, if you're on Win32, there is no fork.
0
 

Author Comment

by:faur
ID: 1206640
Yes, that's a WIN32 (WindowsNT)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206641
Bad luck: single user, single tasking :-(

Never tested (and can't at the moment), try to use NT's _spawn()
system call. Don't know if you need a libc (comes with any compiler) installed for that.
0
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1206642
Not! Not single user, not single tasking.  

Actually, just create a seperate perl script that will handle the SMTP code. call that script, say, DoSMTP.pl (nifty, no?)

Then

use Win32::Process;
use Win32;

my($Process);
Win32::Process::Create($Process,
                                    "C:\\perl.exe", # or whereever
                                    "perl DoSMTP.pl arg1, arg2, etc, manyargs",
                                     0,
                                     NORMAL_PRIORITY_CLASS,
                                     ".")
         || die "CreateProcess Error: ",Win32::FormatMessage(Win32::GetLastError()), " ";

for More info , check perldoc Win32::Process

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206643
hey b2pi, nice answer (I was shure that there must be something in perl, just didn't know it; I'm not familar with Win32).
About your example, should it be:
    "perl", "DoSMTP.pl", "arg1", "arg2", "etc", "manyargs",
instead of:
    "perl DoSMTP.pl arg1, arg2, etc, manyargs",
(similar to _spawn() ).

BTW, if there are only 2 possibilities: single- vs. multi-tasking
then NT is single, it's just multi-threaded (it's not my statement, it's just what I can read in M$ descriptions). Anyway, the difference may be theoretically. But NT 4.0 is definitely single user, 'cause there is no possibility to have more than one user full access (login) to the same system.

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206644
The code should be as I wrote it.

Further, I can't think of a single metric that would argue that NT is single tasking.  Finally, it is indeed possible to have more than one user have full access to the same system (in a trivial example, yes, Virginia, there is a telnetd daemon)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1206645
b2pi, it was just a question: I understand now that the arduments
are  "arg1,"  and  "arg2,"  and so on ..

Further, telnetd ok, then please start notepad :-O
0
 

Author Comment

by:faur
ID: 1206646
Thanks man!
That worked.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question