代码之家  ›  专栏  ›  技术社区  ›  Justin

有一个mod_perl2/Perl 5等效于PHP的ignore_user_abort()吗?

  •  1
  • Justin  · 技术社区  · 17 年前

    我正在编写一个内部服务,需要为长时间运行的进程接触mod_perl2实例。该作业是从HTTP POST触发的,它们的mod_perl处理程序会接收它并完成工作。这可能需要很长时间,并且可以异步处理,所以我希望我可以在HTTP连接运行时终止它。

    ignore_user_abort()

    2 回复  |  直到 17 年前
        1
  •  3
  •   Justin    17 年前

    好吧,我想出来了。

    Mod_perl在这里有PHP的“相反”问题。默认情况下,mod_perl进程保持打开状态,即使连接被中止,PHP默认关闭进程。

    Practical mod_perl book

    #setup headers
    $r->content_type('text/html');
    $s = some_sub_returns_string();
    
    $r->connection->keepalive(Apache2::Const::CONN_CLOSE);
    $r->headers_out()->{'Content-Length'} = length($s);
    
    $r->print($s);
    $r->rflush();
    
    #
    # !!! at this point, the connection will close to the client
    #
    
    #do long running stuff
    do_long_running_sub();
    
        2
  •  0
  •   Community Mohan Dere    9 年前

    您可能想考虑为此使用作业队列。这是 one

    这是另一条关于 this 问题和a article 关于一些php选项。我不是perl monk,所以我会把这些工具的建议留给其他人。

    推荐文章