return response to from php to ajax before script finishes
<p>I have a simple AJAX request that to a PHP file. Once the PHP script reaches a certain point I would like for the response to be completed and sent back to the client. After that I still need the PHP script to run a function that takes up to 15 seconds. Currently the browser waits for the entire PHP script to finish before processing the response. I have tried to use <code>flush();</code> or <code>ob_flush();</code>, but it still waited for the PHP script to finish running before sending the response.</p>

<p>JQuery code:</p>

<pre><code>jQuery.ajax({
            url: "../phpFile.php",
            data: formdata,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (data) {
                data = $.parseJSON(data);
                if(data.success){
                    window.location = "../public/dashboard.php";
                }
           }
});
</code></pre>

<p>PHP code:</p>

<pre><code>if ($script_reached_this_point) {

    // ob_start();
    echo json_encode(['success' =&gt; 'Ticket added']);
    //flush();
    //  ob_end_flush();

    run_15_second_function();

}
</code></pre>