如何将 url 或变量从 Perl 传递到 PHP? [英] How can I pass a url or variable from Perl to PHP?
问题描述
我有两个现有的脚本,可以单独使用.
I have two existing scripts that work fine as individuals.
主要脚本是 Perl.我希望从 Perl 脚本中的子程序执行 PHP 脚本.
The main script is Perl. I wish to execute the PHP script from a sub in the Perl script.
通常,PHP 脚本只是通过直接 url 运行,例如http://me.com/phpscript.php?foo=bar
Usually, the PHP script is just run via direct url e.g. http://me.com/phpscript.php?foo=bar
我只想从 Perl 调用 PHP 脚本并传递 foo var,所以我不需要用浏览器点击 PHP 脚本来处理数据.
I would like to just call the PHP script from the Perl and pass the foo var so, I don't need to hit the PHP script with my browser to process the data.
我没有足够的天赋将 PHP 脚本重写为 Perl.
I am not talented enough to rewrite the PHP script to Perl.
我试过 exec("http://me.com/phpscript.php?foo=bar");并包括和系统无济于事.
I tried exec("http://me.com/phpscript.php?foo=bar"); and include and system to no avail.
我已经阅读并搜索过,但只找到了从 PHP 调用 Perl 的解决方案.
I have read and searched but, found only solutions to call Perl from PHP.
我真的很感谢我在这里一直很好的伟大指导.
I really appreciate the great guidance I always fine here.
推荐答案
似乎 LWP::UserAgent 应该适用于这种情况.
Seems like 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;
}
这篇关于如何将 url 或变量从 Perl 传递到 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!