问题
Some of the functions I am planning for a new site of mine are already available as free Perl modules. Hence I am looking at the possibility of using them, rather than coding them again in PHP. I was planning to use exec
or system
function to call the perl script, which will be slow. But I came across a pecl extension which allows PHP to interpret perl code.
Will this affect the performance of my other php pages, which are not using the perl script? I understand that the extra module will increase my memory usage, but other than that, will there be any issues?
回答1:
It looks like all it is doing is embedding perl
inside the PHP process. You should see a memory increase of a few megabytes plus any data you create in Perl. It should not slow down any code. It is just another library sitting in memory waiting for you to call it. There are two benefits of this solution: you don't have to waste time spawning another process and you don't have to parse the return values from text being printed.
Another solution is to write a Perl daemon and talk to it over a domain socket, pipe, or some other method of IPC.
You might also be interested in the Perl documentation covering embedding perl.
回答2:
Are these Perl modules providing something that simply isn't available in native PHP? Or are they simple enough for you to convert them to PHP?
In other words, do you really need to run Perl code here?
Even if you don't affect performance, you will affect the maintainability of your system by adding languages.
There are times when you do need to interface between languages, but to me this doesn't sound like one of them. It sounds to me as if you'd be much better served finding or writing an equivalent bit of code in PHP.
You say in a comment elsewhere that the Perl code "just provides some handy functions like whois lookup", so I did a quick google and found this: http://www.phpwhois.org/. There were lots of other relevant looking results as well.
来源:https://stackoverflow.com/questions/4276654/perl-interpreter-for-php