gpt4 book ai didi

Perl 重定向浏览器并继续处理

转载 作者:行者123 更新时间:2023-12-04 19:35:26 25 4
gpt4 key购买 nike

这工作正常(重定向到不同的域):

#! /usr/bin/perl 
print "Location:http://AnyDomainBesidesMyOwn.com/\n\n";
close(STDOUT); close(STDIN); close(STDERR);
[some long process]

但是下面的方式会拖延浏览器,拒绝重定向,直到漫长的过程完成。与上面的唯一变化是我重定向到运行脚本的同一域上的另一个页面。
#! /usr/bin/perl 
print "Location:http://MyOwnDomain.com/\n\n";
close(STDOUT); close(STDIN); close(STDERR);
[some long process]

我知道我可以通过 fork 一个新进程来让它工作,但是必须有一个更简单的方法......对吧?

更新:这是我从 Firefox 中的 Live Headers 获得的输出:
http://example.com/test3.cgi 

GET /test3.cgi HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 302 Found
Date: Sun, 27 Jan 2013 23:31:49 GMT
Server: Apache
Location: http://example.com/
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 187
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

然后在它设计重定向之后:
http: //example.com/ [Have to include the space b/c stackoverflow limits the number of links I can include in a post]

GET / HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 200 OK
Date: Sun, 27 Jan 2013 23:31:54 GMT
Server: Apache
Accept-Ranges: bytes
X-Mod-Pagespeed: 0.10.21.2-1381 [Same problem even on a domain w/o pagespeed installed]
Vary: Accept-Encoding
Content-Encoding: gzip
MS-Author-Via: DAV
Cache-Control: max-age=0, no-cache
Content-Length: 12189
Keep-Alive: timeout=2, max=99
Connection: Keep-Alive
Content-Type: text/html

最佳答案

我相信经过反复试验,我已经找到了解决方案。关键是用fork()并退出父进程。然后关闭子进程中的所有文件句柄:

#!/usr/bin/perl

print "Location: ../myHomePage.htm\n\n";

exit 0 if fork();
close(STDIN);
close(STDOUT);
close(STDERR);

# do some long process
open(SM, "| /usr/sbin/sendmail -ti -odq);



就我而言,邮件程序需要几秒钟才能接受消息并将其排队。该网页似乎非常缓慢。执行上述操作后,重定向立即发生,几秒钟后消息出现在邮件日志中。

关于Perl 重定向浏览器并继续处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com