Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

PHP page with perl

Hi guys I hope you can clear this up for me.

I have the following situation.

Client MachineA
Client MachineB

Clients A and B will open up a web page and point to http://serverA/index.php

On ServerA,
I have perl scripts that when I run locally (that is, logged into ServerA through telnet), target the server called ServerB. These perl scripts only exist on ServerA to connect to and retrieve information from Server B.

What Im hoping is possible is the following.....

Clients open up a web page to ServerA.
Coded in PHP on ServerA eg.index.php on ServerA, are perl commands that launch the perl scripts on ServerA, that point to ServerB, collect information back from ServerB, and display on the index.php page to the Clients.....that is, the Clients click on buttons on serverA/index.php, which retrieve information about ServerB, and displayed to these clients.

So, in other words.....

ClientA/B ------------> http://serverA/index.php ----------------------> results of
                                          clientA user                                                 displayed in index.php
                                          clicks on a button                                           to users/s at clientA/B
                                          which launches
                                   perl -s serverB

Is this possible, or would I have to publish the serverA/index.php as a citirx web application since the perl scripts being executed ONLY exist on serverA? Or, because php is server-side, if I code into the index.php page a perl script which exists only locally on serverA, can the users of clientA/B launch these perl scripts, which would execute FROM serverA?

Any help appreciated.
Avatar of miqrogroove
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
On serverA/index.php you can use CURL to execute your perl script on server b:
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
$response = curl_exec($ch);

// close cURL resource, and free up system resources

echo $response;

$output = shell_exec('perl -s');
For more info look at the curl examples here:
Avatar of Simon336697


Hi hielo!

Thank you so much for your kind answers hielo.


the perl scripts are physically located on SERVERA.

It is on ServerA that I wish to execute them.

The perl scripts simply reference ServerB in their commands.

So basically, I want users of clientA and B machines to open up a web page to serverA.


In the code of index.php, is some code which executes a perl script physically located on serverA.

The results of that execution of the perl script are then returned to the clientA's browser in serverA/index.php

Is the curl statement still the way to go in this case?
I think all you need is echo shell_exec()
>>Is the curl statement still the way to go in this case?
No. No needed at all. All you need in that case is to use this as your ServerA/index.php:
$output = shell_exec('perl -s');
echo $output;
Thank you again you nice people.
Im having problems with formatting in the shell_exec statement the following....

At a command line, it looks like the following...

E:\>perl --server serverB --datacenter "Out Data Center" --username domain\username --password "password"

When i kick off the above, it works.

How guys do I put this into:

$output = shell_exec('perl -s');
echo $output;

where the 'perl -s'
is replaced with...

E:\>perl --server serverB --datacenter "Out Data Center" --username domain\username --password "password"

echo shell_exec('perl --server serverB --datacenter "Out Data Center" --username domain\username --password "password"');
Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi mi, hielo!

Guys serverA is a windows box.

Do I need to escape backslashes ?


perl e:\
perl e:\\ (double backslash?

echo shell_exec('perl e:\\ --server serverB --datacenter "Out Data Center" --username domain\username --password "password"');
I believe so. Try it, but be consistent. You are not escaping it on domain\username. Try it like this:

echo shell_exec('perl e:\\ --server serverB --datacenter "Out Data Center" --username domain\\username --password "password"');

If that does not work, try it with single slashes, but again, be consistent.
NO do not add slashes!  Slashes only get escaped in double-quoted strings.
You guys are fantastic.
That works like as follows...

echo shell_exec('perl e:\ --server serverB --datacenter "name" --username domain\username --password "password"');

I cant thank both you, hielo, and miqrogroove, enough.
All the very best to you both.