Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Run Perl script on remote server

by hmb104 (Sexton)
on Feb 14, 2013 at 15:40 UTC ( #1018746=perlquestion: print w/ replies, xml ) Need Help??
hmb104 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I have the following situation and I'm looking for suggestions.

* Scripts reside in server A (Has Perl modules installed)

* Webserver is B (no Perl and policy said we can't install)

I would like to run my Perl script on webpages. So that means some how to call them using PHP or anything else and they get executed in server A and return the output to server B to capture it and return it to user.

Any suggestions or comments?

Best regards,

hm

Comment on Run Perl script on remote server
Re: Run Perl script on remote server
by blue_cowdawg (Monsignor) on Feb 14, 2013 at 15:51 UTC
        • Scripts reside in server A (Has Perl modules installed)
        • Webserver is B (no Perl and policy said we can't install)

    What sort of environment are you running in that won't allow Perl to be installed (or doesn't already have Perl installed?)

    Once solution to this would be to convert your scripts on Server A into a web service and communicate back to the PHP scripts running on Server B via JSON encoded messages or some such.

    Take a look at the path_info() method of the module CGI for some ideas on how to implement this. It is a quick and dirty way of implementing something that sorta looks like a RESTFull service.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Run Perl script on remote server
by daxim (Chaplain) on Feb 14, 2013 at 16:01 UTC
    Simple: open a pipe to ssh.

    Or run your Perl programs in a Web server, and write a PHP HTTP client for them (fopen, curl).

    If that is not possible or sufficient, then you're looking for RMI/distributed computing (or conceptionally equivalent). If you have no idea where to start, simply run a Perl SOAP server and PHP SOAP client, SOAP sucks hairy donkey balls but at least it's painless in PHP. There are many more protocols (XML-RPC, JSON-RPC, Corba, …) and you can invent your own protocol (on top of sockets, on top of HTTP, …).

      Or run your Perl programs in a Web server, and write a PHP HTTP client for them (fopen, curl).

      I did that once and it works very well - POST and GET values can be passed on as is and the testing can be done on the server with Perl while completely ignoring the one with PHP ( Server A ).

      The only downsides are:

      • Cross domain scripts sometimes give the user a scary error
      • The browser will render nothing until the entire HTML is thrown out which might make page loads appear slow to the user - You cant flush STDOUT halfway to get the browser to start rendering stuff.

Re: Run Perl script on remote server
by necroshine (Acolyte) on Feb 14, 2013 at 16:09 UTC
    I think you can use 'gearman' to spawn a job from PHP and receive a serialized result from PHP. After this you can use PHP::Serialization(CPAN) to deserialize or JSON to bring the results with Perl(JSON probably is more simple). Gearman site:

    Off course you will need to install Gearman in A and B servers. If you can´t do this, you can use simple sockets to get results from PHP and finally process with Perl anyway.

    Necroshine
Re: Run Perl script on remote server
by karlgoethebier (Curate) on Feb 14, 2013 at 19:19 UTC

    I have a problem to understand this task.

    Perhaps you can provide a more detailed example?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: Run Perl script on remote server
by jfroebe (Vicar) on Feb 14, 2013 at 20:58 UTC

    From what it sounds like is that you're trying to get around a PHP development mandate by, presumably, your employer. At least that's what is coming across to me. If that is the case, then you're better off making a business case for using Perl as well as PHP else you might be in a wee bit of trouble with the web server folk.

    We definitely need a better description of what you're trying to accomplish so we can help you do the right thing, whatever that is. :)

    Jason L. Froebe

    Blog, Tech Blog

Re: Run Perl script on remote server
by Anonymous Monk on Feb 14, 2013 at 21:14 UTC
    Given the fact that I don't know the particulars... Would it be possible to use reverse proxying to forward requests to Webserver B along to server A? Easy to implement if your environment supports it.
Re: Run Perl script on remote server
by Anonymous Monk on Feb 14, 2013 at 22:24 UTC
    If speed is an issue, Create the page on server B as a template with specific DIVs labeled to hold the dynamic content. Use AJAX and jQuery to load the html as a string from server B. Then insert the text into the appropriate DIVs using their labels. Throw a nice loading gif as a placeholder and bam, good to go. No blank page while waiting for the AJAX loads.
Re: Run Perl script on remote server
by Anonymous Monk on Feb 14, 2013 at 23:42 UTC
    Set up server-A as a "FastCGI" host that is communicated-with by server-B using "mod_fastcgi" or its equivalent on Apache. "B" doesn't have to be generally accessible; only accessible to "A."
Re: Run Perl script on remote server
by igelkott (Curate) on Feb 15, 2013 at 00:27 UTC

    Could package your Perl scripts on A with pp. Copy and run the package on B to get some benefit of Perl without actually installing.

    Of course, this probably violates the "spirit" of the policy but may in fact be permitted.

Re: Run Perl script on remote server
by Anonymous Monk on Feb 15, 2013 at 02:10 UTC

    Whisper it quietly, but the easiest, most efficient and stable solution is probably to bite the bullet and re-write the script in PHP.

    It should only take a couple of days to learn enough PHP to do this for most scripts.

    I prefer Perl, but if someone wants to pay me to write PHP I'm up for it.

    J.C.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018746]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-09-23 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls