PHP 的 Perl 解释器

发布于 2024-10-04 13:07:39 字数 368 浏览 5 评论 0原文

我为我的新站点计划的一些功能已经作为免费 Perl 模块提供。因此,我正在考虑使用它们的可能性,而不是在 PHP 中再次编码。我打算使用execsystem函数来调用perl脚本,这会很慢。但我遇到了一个 pecl 扩展,它允许 PHP 解释 perl 代码

这会影响我的其他未使用 perl 脚本的 php 页面的性能吗?我知道额外的模块会增加我的内存使用量,但除此之外,还会有任何问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑶笙 2024-10-11 13:07:39

看起来它所做的只是将 perl 嵌入到 PHP 进程中。您应该会看到内存增加了几兆字节以及您在 Perl 中创建的任何数据。它不应该减慢任何代码的速度。它只是另一个位于内存中等待您调用的库。此解决方案有两个好处:您不必浪费时间生成另一​​个进程,也不必解析正在打印的文本的返回值。

另一种解决方案是编写一个 Perl 守护程序并通过域套接字、管道或某些其他 IPC 方法与其通信。

您可能还对涵盖 嵌入 perl 的 Perl 文档感兴趣。

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.

浅暮の光 2024-10-11 13:07:39

这些 Perl 模块是否提供了本机 PHP 中无法提供的功能?或者它们足够简单,您可以将它们转换为 PHP 吗?

换句话说,您真的需要在这里运行 Perl 代码吗?

即使不影响性能,添加语言也会影响系统的可维护性。

有时您确实需要在语言之间进行交互,但对我来说,这听起来不像其中之一。在我看来,如果您在 PHP 中找到或编写等效的代码,效果会更好。

你在其他地方的评论中说 Perl 代码“只是提供了一些方便的功能,比如 whois 查找”,所以我快速谷歌了一下,发现了这个: http://www.phpwhois.org/。还有很多其他相关的结果。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文