我想运行一些代码,比如调用需要时间的大型数据库或网络活动。
那么如何在后台执行此操作以及阻止浏览器等待后台进程结束而不会终止任何进程或破坏任何流程
#!/usr/bin/perl
sub async_process{..what code..}
&async_process;
$T=time;
print "Content-type: text/html; charset=utf-8\n\n";
print "$T";
exit;
答案 0 :(得分:1)
sub async_process{
my $pid = fork(); return if $pid; # creates new child process, and parent moves on
close STDIN;close STDOUT; # releases browser from waiting child to finish
# code goes here
sleep 10;
$T=time;open(_fh,">file.txt");print _fh "$T";close(_fh);
exit;
}