How to pass a url or variable from Perl to PHP?

I have two existing scripts that work great as people.

The main script is Perl. I want to execute a PHP script with a sub in a Perl script.

Typically, a PHP script is run through a direct URL, for example. http://me.com/phpscript.php?foo=bar

I would just like to call a PHP script from Perl and pass foo var, so I don’t have to delete the PHP script from my browser to process the data.

I'm not talented enough to rewrite a PHP script in Perl.

I tried exec ("http://me.com/phpscript.php?foo=bar"); and turn on the system to no avail.

I read and searched, but found only solutions for calling Perl from PHP.

I really appreciate the great leadership, which I am always wonderful here.

+1
source share
4 answers

It seems that LWP :: UserAgent should work for this scenario.

require LWP::UserAgent;

 my $ua = LWP::UserAgent->new;
 $ua->timeout(10);
 $ua->env_proxy;

 my $response = $ua->get('http://me.com/phpscript.php?foo=bar');

 if ($response->is_success) {
     print $response->decoded_content;  # or whatever
 }
 else {
     die $response->status_line;
 }
+1
source

If the script is in the local file system, you can execute it directly using the PHP interpreter and the file path. To access it over the Internet, use the package LWP.

For instance:

exec('/usr/bin/php', 'myscript.php', @arguments);

Note that command line arguments are handled differently than URL arguments; your PHP script will probably need to be modified to use them correctly.

0
source

php , #! PathToPhp

  ./myscript.php

argc argv args , , args

  #!/bin/php
  <?php
  foreach($args as $key => $value){
   echo "\n".$key.":".$value;
0

CPAN, PHP Perl:

PHP5 intepreter. - ( AUTOLOAD) , PHP, Perl PHP ( ) PHP Perl Perl.

- PHP- Perl --.

, .

0

All Articles