如何将 Perl 代码从 mod_perl 移植到 FastCGI?
我们有一个支持 mod_perl
的现有 Perl 应用程序。 然而,我们的新主机(Dreamhost)不支持mod_perl,仅支持FastCGI; 因此需要端口。
现有代码不使用任何 Apache 特定的内容,只是以 mod_perl
可接受的方式编写的普通 Perl 代码。
阅读文档和在线教程,添加 FastCGI 支持似乎涉及将现有代码包装在特定类型的循环中。 以下是最常见的骨架代码:
A. 使用FCGI
use FCGI;
while (FCGI::accept >= 0)
{
#Run existing code.
}
B. 使用 CGI::Fast
use CGI::Fast
while (my $cgi = CGI::Fast->new())
{
#Run existing code.
}
子问题:
- 方法 A 和 B 是否是添加 FastCGI 支持的等效方法?
- 如果A和B不同,那么使用其中一个与另一个相比有何优缺点?
- 从
mod_perl
移植到 FastCGI 时,是否有应该了解的最佳实践或陷阱?
谢谢。
We have an existing Perl application that supports mod_perl
. However, our new host (Dreamhost) does not suppport mod_perl, only FastCGI; thus necessitating the port.
The existing code does not use any Apache specific stuff and is just normal Perl code written in way that's acceptable to mod_perl
.
Reading the documentation and online tutorials, it appears that adding FastCGI support involves wrapping existing code inside a specific kind of loop. Below are the most commonly given skeleton code:
A. Using FCGI
use FCGI;
while (FCGI::accept >= 0)
{
#Run existing code.
}
B. Using CGI::Fast
use CGI::Fast
while (my $cgi = CGI::Fast->new())
{
#Run existing code.
}
Sub-Questions:
- Are methods A and B equivalent ways to add FastCGI support?
- If A and B are different, what then are the pros and cons of using one over the other?
- Are there any best practices or gotchas one should know about when porting from
mod_perl
to FastCGI?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,FastCGI 应用程序与 CGI 非常相似。 主要区别在于您可以利用您的流程能够持久的事实。 您可以利用它在应用程序中获得速度优势,例如,您可以在运行的进程中缓存数据库数据。 本质上,您将应用程序更改为自己的应用程序服务器,在 Web 服务器提供的 FastCGI 网关后面运行。
这个想法是弄清楚如何使应用程序的处理方式适用于 FastCGI 网关。 您使用任何 mod-perl 特定功能吗? 如果是这样,请远离它。 如果没有,那么就开始通过 FastCGI 进行对话。 您的优势在于 Perl 可以使用 FastCGI 接口。 我假设您正在使用某种版本控制系统,因此只需创建一个用于移植到 FastCGI 的分支即可。 然后,开始将 POST 和 PUT 视为从标准输入读取,并将应用程序的响应视为写入标准输出。
您可能还想通读为应用程序实现 FastCGI 接口的库。 您可以在 fastcgi.com 上找到其中一些内容。 这可能有助于您了解应用程序将执行的操作与当前执行的操作不同。
祝你好运!
Generically speaking, a FastCGI application is very similar to CGI. The major difference is that you can take advantage of the fact that your process is able to be persistent. You can leverage that to gain speed advantages in your application—for example, you can cache database data in your running process. Essentially, you're changing your application into its own application server, running behind a FastCGI gateway provided by the Web server.
The idea is to figure out how to make your application's means of processing applicable to a FastCGI gateway. Do you use any mod-perl specific functionality? If so, move away from that. If not, then just start working on talking via FastCGI. You've an advantage in that there are FastCGI interfaces available for Perl. I assume that you're using some sort of a version control system, so just make a branch that is for porting to FastCGI. Then, just start thinking about POST and PUT as reading from standard input and your application's responses as writing to standard output.
You may want to also just read through a library that implements a FastCGI interface for an application. You can find some of those at fastcgi.com. That might help for you to understand what your application is going to be doing differently in relation to what it is doing currently.
Good luck!
快速查看 CPAN 文档,看起来 CGI::Fast 是 FCGI 的包装;
来自 CGI::Fast 页面:
我的看法是,它基本上可以让您使用 CGI.pm 的标准功能以及 FastCGI 的速度优势(标头创建和参数访问是 CGI 的主要方面。 pm 你可能已经在使用了)。
我没有使用过其中任何一个,这只是我从文档中看到的样子,所以我很可能是错的。
From quickly looking at the CPAN docs, it looks like CGI::Fast is a wrapper around FCGI;
from the CGI::Fast page:
My take is that it basically lets you use the standard functionality of CGI.pm with the speed benefits of FastCGI (header creation and parameter access being the main aspects of CGI.pm you are probably already using).
I haven't used either of these, this is just what it looks like to me from the documentation, so I could well be wrong.