如何在Perl中编写Web应用程序,以便它可以作为普通的CGI脚本,FastCGI/FCGI脚本和mod_perl/ mod_perl2(最好只使用核心Perl模块和来自libwww-Perl的模块),并最大限度地减少Perl CPAN模块的数量必须安装)?我想尽量减少将脚本从使用CGI更改为使用FastCGI或mod_perl的脚本所需做的更改.
进一步的约束:如果可能的话,我想在单个文件中记录Web应用程序,而不是像目前那样将它拆分为模块.
有问题的网络应用程序是gitweb,Git web界面,如果重要的话.
我们最近推出了一个新的Django支持的网站,我们遇到了最奇怪的错误:
该站点在Apache下使用mod_fastcgi运行.一切正常,然后URL标记和reverse()功能停止工作.它们返回""而不是返回预期的URL.
我们在Apache的日志文件中没有注意到任何内容; Django没有生成错误.而且(踢球者)问题只发生在生产模式中; 当DEBUG = True时,我们无法重现它.
关于我们应该在哪里寻找问题的任何想法?
更新:事实证明这是settings.LANGUAGES的一个问题,虽然我们还没有确定为什么破坏了东西.
我正在运行Windows,安装了IIS 7.5,PHP 5.3(FastCGI).试图连接到MySQL和得到一个错误"连接尝试失败,因为连接的方没有正确一段时间后响应或已建立的连接失败,因为连接的主机未能响应."
开始使用XAMPP开发项目,但是需要将其移动到IIS(因为AD身份验证).MySQL从XAMPP堆栈运行.我已经将IIS映射到与Apache2相同的docroot,但是映射到另一个端口.使用Apache2主机访问测试页面服务器时 - 没有问题,但是当访问IIS + PHP FCGI页面时 - 我收到此错误.
试图在FastCGI下运行旧的CGI脚本.没有额外参数的打印可提供正确的输print $q->div( $q->param("text") )
但是当使用CGI方法的额外参数哈希打印出来时print $q->div( {-id=>"id"}, $q->param("text") ),它会破坏UTF-8形成的数据('õäöüžš' - >'ÃμÃÃÃÃÃÃÃüüžš
它只发生在CGI参数中,在脚本定义的变量中工作正常(例3和4).在普通的CGI(带有"-utf8"-flag)下,一切都很完美.
被称为FastCGI的示例脚本test.fcgi?text=õäöüžš应该给出四个相等的块:
#!/usr/bin/perl -w --
use strict;
use CGI::Fast qw(:all);
use locale;
use utf8;
BEGIN {
binmode(STDIN); # Form data
binmode(STDOUT, ':encoding(UTF-8)'); # HTML
binmode(STDERR, ':encoding(UTF-8)'); # Error messages
}
my ($q) = ();
my $test = "õäöüžš";
while ($q = new CGI::Fast) {
print $q->header(-type=>"text/html", -charset=>"utf-8"),
$q->start_html(-encoding=>"utf-8");
print "1: ",
$q->div( $q->param('text') ),
"<br />",
"2: ",
$q->div( {-id=>"id"}, $q->param('text') ),
"<br />", …Run Code Online (Sandbox Code Playgroud) 我有一个运行报告的PHP应用程序,并在90秒内向SQL服务器发出大约100万个SQL查询.在此期间,没有其他人可以使用这个基于Web的应用程序 - 鸡蛋计时器正在滚动,但在报告超时或完成之前没有任何内容加载.我在一个孤立的环境中测试了这个问题,只有我自己在那里,在浏览器中运行报告,然后从其他浏览器窗口到此应用程序站点的任何操作都挂起.
有关测试环境的一些细节:
Windows 2008 R2 x64 - IIS 7.5 - PHP 5.3.8 via FastCGI
Windows 2008 R2 x64 - SQL Server 2008 R2 x64
Run Code Online (Sandbox Code Playgroud)
IIS中的FastCGI设置:
Instance MaxRequests = 200
Max Instances = 16
Activity Timeout = 70
Idle Timeout = 300
Queue Length = 1000
Rapid Fails PerMin = 10
Request Timeout = 90
Run Code Online (Sandbox Code Playgroud)
每个SQL请求在SQL服务器端完成不到60毫秒.Web服务器和SQL服务器的CPU负载均小于10%.运行报告时,Web服务器具有16GB RAM,大约60%的RAM可用.
看起来,PHP已经向SQL服务器发出了太多请求,并且变得太忙而无法处理其他请求.如果是这种情况,那么应该有一些我可以调整以使PHP处理更多并发请求的东西.
有人知道吗?请帮忙!
我在Webmin上使用Virtualmin在VPS上配置我的网站.
一切都运行正常,但现在我尝试创建一个新域,但是当我把文件放入其中时,public_html它会让php文件下载而不是执行它.怎么解决这个问题
这些是我的apache配置(找不到任何奇怪的东西):
/etc/apache2/sites-available/testbyc.--.nu.conf
SuexecUserGroup "#1009" "#1011"
ServerName testbyc.--.nu
ServerAlias www.testbyc.--.nu
ServerAlias webmail.--.--.nu
ServerAlias admin.testbyc.--.nu
DocumentRoot /home/byc/domains/testbyc.--.nu/public_html
ErrorLog /var/log/virtualmin/testbyc.--.nu_error_log
CustomLog /var/log/virtualmin/testbyc.--.nu_access_log combined
ScriptAlias /cgi-bin/ /home/byc/domains/testbyc.--.nu/cgi-bin/
ScriptAlias /awstats/ /home/byc/domains/testbyc.--.nu/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/byc/domains/testbyc.--.nu/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/byc/domains/testbyc.--.nu/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/byc/domains/testbyc.--.nu/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/byc/domains/testbyc.--.nu/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.testbyc.--.nu
RewriteRule ^(.*) https://testbyc.--.nu:20000/ [R] …Run Code Online (Sandbox Code Playgroud) 我正在阅读nginx的文档,但我不知道这个'(?U)'正在这个正则表达式中做什么.
http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_path_info
这是一个例子.脚本show.php接收字符串文章/ 0001作为参数.以下配置将正确处理路径拆分:
location ~ ^.+\.php {
(...)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
(...)
}
Run Code Online (Sandbox Code Playgroud)
请求/show.php/article/0001将SCRIPT_FILENAME设置为/path/to/php/show.php,将PATH_INFO设置为/ article/0001.
这个正则表达式还不够?
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
Run Code Online (Sandbox Code Playgroud)
谢谢
当我的服务器突然停止工作时,一切都运行得很顺利.我正在使用Linode和Nginx fast-cgi
这是我的日志文件:
上游超时(110:连接超时),同时从上游读取响应头,客户端:76.66.174.147,服务器:iskacanada.com,请求:"GET/HTTP/1.1",上游:"fastcgi://127.0.0.1: 9000",主持人:"www.iskacanada.com"
location ~ \.php$ {
include fastcgi_params;
fastcgi_read_timeout 120;
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Run Code Online (Sandbox Code Playgroud)
当我想重启mysql时,它说:
sudo service mysql restart stop:未知实例:start:作业无法启动
怎么知道发生了什么?
我有运行Apache 2.2.4和PHP-FPM(FastCGI Process Manager)的VPS服务器(CentOS 6.5).每天2-3次我得到以下错误error_log:
[error] [client 127.60.158.1] (4)Interrupted system call: FastCGI: comm with server "/usr/lib/cgi-bin/php5-fcgi" aborted: select() failed
[error] [client 127.60.158.1] FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi"
[notice] caught SIGTERM, shutting down
[alert] (4)Interrupted system call: FastCGI: read() from pipe failed (0)
[alert] (4)Interrupted system call: FastCGI: the PM is shutting down, Apache seems to have disappeared - bye
Run Code Online (Sandbox Code Playgroud)
因此,apache并不总是停止,有时只有主进程停止并且工作进程仍然运行,这使我甚至无法重启apache,因为它仍在侦听端口80,但没有主进程和pid文件.
我看到有人提到要更新到mod_fastcgi 2.4.7(修补)修复了这个bug,但不幸的是RHEL/CentOS没有更新,所以这对我来说不是一个选项.(Apache PHP5-FPM连接由同行重置)
谷歌的答案还有线程,--idle-timeout在fastcgi.conf 中增加价值可以解决问题,但我没有看到原因.
请问这个问题的解决方案吗?
我正在尝试使用Apache2(Apache/2.4.6(Ubuntu))运行cgi脚本fastcgi_module.这是我设置的虚拟主机
<VirtualHost *:8080>
ServerName cgi.local
DocumentRoot /home/noobeana/CGI
<Directory /home/noobeana/CGI>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler fastcgi-script
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这是我创建的用于运行测试()的Perl脚本(正确775'/home/noobeana/CGI/test.pl):
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello there!<br />\n";
Run Code Online (Sandbox Code Playgroud)
Perl可执行文件的路径确实是/usr/bin/perl其他一切看起来很好,但是当我在浏览器中打开http://cgi.local:8080/test.pl时,脚本会永远运行 - 我必须停止Apache强制退出.此外,print正在输出到Apache的错误日志(而不是浏览器),只要脚本正在运行,它就会显示以下多行:
[Fri Feb 07 10:24:54.059738 2014] [:warn] [pid 4708:tid 140365322880896] FastCGI: (dynamic) server "/home/noobeana/CGI/test.pl" started (pid 4771)
Content-type: text/html
Hello there!<br />
[Fri Feb 07 10:24:54.078938 …Run Code Online (Sandbox Code Playgroud)