简体   繁体   English

如何在不使用curl和apache2的情况下在本地使用Perl CGI?

[英]How do I use a Perl CGI locally without using curl and apache2?

I would like to submit a form to a CGI script localy (w3c-markup-validator), but it is too slow using curl and apache , I want to use this CGI script more than 5,000 times in an another script. 我想将表单提交到CGI脚本语言环境(w3c-markup-validator),但是使用curlapache太慢了,我想在另一个脚本中使用此CGI脚本超过5,000次。 and currently it takes more than one hour. 目前需要一个多小时。

What should I do to give the form directly to the CGI script (I upload a file with curl )? 如何将表单直接提供给CGI脚本(我使用curl上传了文件)?

edit: It seems to be too complicated and time consuming for what I needed, so I waited 1 hour and a half, each time I needed to test my generated xhtml files. 编辑:对于我需要的东西来说似乎太复杂且耗时,因此每次需要测试生成的xhtml文件时,我等待了一个半小时。 In definitive I didn't test any of the answers below, so the question will remain open. 确切地说,我没有测试以下任何答案,因此问题仍然存在。

Depending on the details of the script you might be able to create a fake CGI environment using HTTP::Request::AsCGI and then sourcing the CGI script with the "do" operator. 根据脚本的详细信息,您可能可以使用HTTP :: Request :: AsCGI创建伪造的CGI环境,然后使用“ do”运算符来获取CGI脚本。 But when it comes to speed and maintainability your best bet would be to factor the important part of the script's work into its own module, and rewrite the CGI as a client of that module. 但是,关于速度和可维护性,您最好的选择是将脚本工作的重要部分纳入其自己的模块中,并将CGI重写为该模块的客户端。 That way you don't have to invoke it as a CGI -- the batch job you're talking about now would be just another program using the same module to do the same work, but without CGI or the webserver environment getting in the way. 这样,你不必调用它作为一个CGI -你现在所谈论的将只是使用相同的模块做同样的工作,另一个程序的批处理作业,但没有CGI或Web服务器环境的方式获得。

OK, I looked at the source code for this thing and it is not easy extract the validation stuff from all the rest. 好的,我查看了此内容的源代码,从其余所有内容中提取验证内容并不容易。 So, here is what I would. 所以,这就是我想要的。

First, ditch curl . 首先,沟curl Starting a new process for each file you want to validate is not a good idea. 为要验证的每个文件启动新过程不是一个好主意。 You are going to need to write a driver script that takes a list of URL's and submits them to your local server running on localhost . 您将需要编写一个驱动程序脚本,该脚本将获取URL列表,并将其提交给在localhost运行的本地服务器。 In fact, you might later want to parallelize this because there will normally be a bunch of httpd processes alive anyway. 实际上,您以后可能要并行化它,因为无论如何通常都会有许多httpd进程处于活动状态。 Well, I get ahead of myself. 好吧,我超越自己。

This script can use LWP because all you are doing is submitting some data to the CGI script on localhost and storing/processing results. 该脚本可以使用LWP,因为您要做的就是向localhost上的CGI脚本提交一些数据并存储/处理结果。 You do not need full WWW::Mechanize functionality. 您不需要完整的WWW :: Mechanize功能。

As for the validator CGI script, you should configure that as a mod_perl registry script . 至于validator CGI脚本,您应该将其配置为mod_perl注册表脚本 Make sure you preload all necessary libraries. 确保预加载所有必需的库。

This should boost documents processed per second from 1.3 to something more palatable. 这应该将每秒处理的文档从1.3提高到更可口。

CGI is a pretty simple API. CGI是一个非常简单的API。 All it does is read data either from an environment variable (for GET requests) or from stdin (for POST requests). 它所做的只是从环境变量(对于GET请求)或从stdin(对于POST请求)读取数据。 So all you need is to do is to set up the environment and call the script. 因此,您所需要做的就是设置环境并调用脚本。 See the docs for details . 有关详细信息,请参阅文档

If the script uses CGI.pm, you can run it from the command line by supplying the '-debug' switch (to CGI.pm, in the use statement.) That will then allow you to send the post variables on stdin. 如果脚本使用CGI.pm,则可以通过提供'-debug'开关(在use语句中为CGI.pm)从命令行运行它,然后使您可以在stdin上发送post变量。 You may have to tweak the script a little to make this work. 您可能需要稍微调整脚本才能使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM