Azure HTTP request timeout workaround

前端 未结 2 1908
终归单人心
终归单人心 2021-01-26 14:16

We currently have an application hosted on a Azure VM instance.

This application sometimes processes long-running and idle HTTP requests. This is causing an issue becau

2条回答
  •  Happy的楠姐
    2021-01-26 14:42

    As a simple workaround, I had my script send a newline character every 5 seconds or so to keep the connection alive.

    Example:

    set_time_limit(60 * 30);
    ini_set("zlib.output_compression", 0);
    ini_set("implicit_flush", 1);
    
    function flushBuffers()
    {
        @ob_end_flush();
        @ob_flush();
        @flush();
        @ob_start();
    }
    
    function azureWorkaround($char = "\n")
    {
        echo $char;
        flushBuffers();
    }
    
    $html = '';
    $employees = getEmployees();
    foreach($employee in $employees) {
        html .= getReportHtmlForEmployee($employee);
        azureWorkaround();
    }
    
    echo $html;
    

提交回复
热议问题