Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

triggering a program in web server

by tja_ariani (Acolyte)
on Aug 18, 2003 at 10:29 UTC ( #284530=perlquestion: print w/replies, xml ) Need Help??

tja_ariani has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks,
I have a structure that consists of a webserver(Server A) and a tcp server (Server B).

First a user will upload a file through a website to the webserver A,
Secondly, when receiving this new file it will automatically trigger a Perl program in A, that will send the uploaded file to Server B.
This second part should be hidden from public.

I have done the website for uploading to A, and have written a simple program for sending the a file to B.

But the problem is, I don't know how to integrate them, i.e. detecting the new uploaded program, and execute/trigger the simple program to send the new file to B.


Replies are listed 'Best First'.
Re: triggering a program in web server
by bm (Hermit) on Aug 18, 2003 at 10:41 UTC
    The first question that comes to my mind is: why do you need two scripts for this? The public cannot read your cgi-script (assuming a correctly configured webserver and filesystem permsissions).

    Having said that....

    Simply call your 2nd program like any other system call ( system, exec, ...) from within your first script.

    Be aware that if you do call an external program, you should:

  • read  perldoc perlsec carefully
  • definitely enable taint checking (perl -T)
Re: triggering a program in web server
by arthas (Hermit) on Aug 18, 2003 at 10:34 UTC


    You can launch the upload-to-B program directly from the script which, on A, receives the file uploaded via web. This might however slow the response to the user down, depending on how fast is the connection between A and B.

    Another option is to have upload-to-B program run as a daemon, which every now and then (how much often you wish) checks for new uploaded files and sends them to B.

    Hope this helps!



      you're rite, I was thinkin to have the program run as a daemon, but I do not know how to do the scheduling part.
      Is there any simple program or piece of code as an example to show how to do this ?

      I was thinkin using infinite loop in the program to check, but will it slow down the server ?
      Or is there any command to 'sleep' the program periodically ?


        A possible approach is: every time a file is uploaded you put a link to that file in a special directory; then every n seconds (via cron or using sleep) you check the directory, move new files and delete links.

        HTH, Valerio

        I was thinkin to have the program run as a daemon, but I do not know how to do the scheduling part.

        Take a look at Net::Daemon . But I can't see the advantage of running this as a daemon is (the small performance gain of not loading Perl?).

Re: triggering a program in web server
by Abigail-II (Bishop) on Aug 18, 2003 at 10:54 UTC
    So, what service do you use on server B? If you really need this convoluted scheme, why not use http to upload the file on server B, the same way it was uploaded to server A? LWP will help you to do this.


Re: triggering a program in web server
by gjb (Vicar) on Aug 18, 2003 at 10:44 UTC

    As an addendum to arthas's post, you may also use a cron facility on server A that runs the transfer program every so often (modified so that it tests whether there's something to trasnfer).

    Just my 2 cents, -gjb-

      Probably the reason why choosing synchronous execution (script A calls script B) or asynchronous is how much time B takes and how you want to handle B's errors. In a synchronous environment you may report B's error to the user (say, destination server is down) and abort the process. If B is expected to be quite fats (say less than a few seconds) handling B synchronously is probably both easier and sensible. If B runs in 'daemon mode', ie as a daemon or using repeated sleep's, you'll have to handle B's errors anyhow using a log or something.
      My $.02

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://284530]
Approved by arthas
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2022-10-03 18:21 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (15 votes). Check out past polls.