Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Running multiple CGI programs

by Stamp_Guy (Monk)
on Sep 17, 2001 at 04:38 UTC ( #112788=perlquestion: print w/replies, xml ) Need Help??

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

I have about 20 CGI programs that I need to be able to run from a single CGI script. There are a set number of parameters that need to be passed to each script. How would you guys suggest going about it? Should I use system calls? I've never done anything like this before, so any advice would be greatly appreciated. Thanks!


Replies are listed 'Best First'.
Re: Running multiple CGI programs
by andreychek (Parson) on Sep 17, 2001 at 04:59 UTC
    Well, it's possible this may not work in your particular case, but I wanted to offer this -- are you certain that you can't move your CGI script code into modules of some sort? If you were capable of doing that -- instead of using an expensive fork call, you could do a simple subroutine call, and just pass parameters that way.

    Another benefit of that method is that it makes it even simpler to move to something like mod_perl. If you're calling 20 CGI programs, the cost of that could be huge.. but if they were Perl modules loaded in mod_perl, the cost of that would actually be quite negligable, aside from RAM considerations. Slashdot uses more modules then that, and they were about the only news site that survived last Tuesday :-)

    If this doesn't work for you, perhaps you could give some more details about the project you are working on. Good luck!
Re: Running multiple CGI programs
by Stamp_Guy (Monk) on Sep 17, 2001 at 06:04 UTC
    Ok, I better explain exactly what I'm doing. I have a template-based website maintenance system. It stores the contents of a web page in text files, which allows the user to update a text file and click a generate button to make it into a web page. The system is a bit more complex than that, but that describes the function in a nutshell. The problem comes in when the text file that holds the menu is changed. The user would then have to click the generate button on each page. What I want to do is make a script that could run all of the scripts so the user didn't have to do that. The script would simply have to call each CGI script like this:

    perl update.cgi?action=generate

    to cause the scripts to generate the pages. Speed isn't so much of a problem because very few people would be updating the site. I hope that clarifies some things. If there are other issues I should clarify, please just let me know. Thanks!

      Thanks for the further explanation. It sounds like you have a problem with mixing interface and implementation. One of my preferred ways to design CGI programs is to have a module that implements the actual functionality and then a CGI front-end that calls that module. If you write your code this way, it's trivial to write a command-line front-end for the module when you need it or to simply call it from another module.

      If you can't deal with that right now and you want a quick and dirty solution, the simplest approach is to use LWP to make additional calls to the server and run the other CGIs. You could simulate a CGI environment by setting environment variables and executing the other programs, but if speed is not an issue there's no reason to do the additional work.

(redmist) Re: Running multiple CGI programs
by redmist (Deacon) on Sep 17, 2001 at 04:59 UTC

    Twenty? It sound like their is a Better Way. Can you tell us some more about the problem space of what you are trying to do?

    Why would you want to fire off 20 CGIs at the same time?

    Purple Monkey Dishwasher

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2019-07-16 18:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found