我想运行一些代码,比如调用一个庞大的数据库或需要时间的网络活动。
那么我该怎么做呢?在后台,同时阻止浏览器等待后台进程结束,而不会杀死任何进程或破坏任何流
#!/usr/bin/perl
sub async_process{..what code..}
&async_process;
$T=time;
print "Content-type: text/html; charset=utf-8nn";
print "$T";
exit;
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;
}