A site Im working on builds a pdf based on the clients input, I have decided that once the purchase is complete thats when the pdf will begin to get generated. The reason is the pdf may be up tp 50/60MB and I dont want the client to have to wait for this to complete.
Im using Opencart and on the checkout success page I have an Ajax command loading a PHP script.
I was under the impression that the user could close the page once the script starts, but for some reason I find I have to wait for 5/10 seconds before closing if I want the file to appear on my server.
Its a little difficult to debug as part of testing involves closing the browser immediately.
Here is my Ajax...
$(document).ready(function() {  
    $.ajax({
        url: 'index.php?route=pdfengine/pdfengine/generate_final_pdf',
        type: 'post',
        dataType: 'json',
        data: {     
        },
        beforeSend: function() {},
        complete: function() {},
        success: function(json) {}
        });
    });
and my php (currently Im loading huge images on it to represent the load time)
 public function generate_final_pdf() {
    include('convert-to-pdf/mpdf.php');
    $mpdf=new mPDF();
    $stylesheet = file_get_contents(DIR_APPLICATION.'view/theme/rascal/stylesheet/stylesheet.css');
    $mpdf->WriteHTML($stylesheet,1);
    $mpdf->WriteHTML('<html><body><div class="pdf-test-style"><img src="http://example.com/top_quality_image.jpg" />test</div><pagebreak><img src="http://example.com/top_quality_image2.jpg" />test<pagebreak><img src="http://example.com/top_quality_image3.jpg" />test</body></html>',2);           
    $mpdf->Output(DIR_FINAL_PDFS.'order_idpdfid-'.$this->session->data['pdf_id'].'.pdf','F');
 }
EDIT:
Just adding more info that Ive tried since reading those articles and seeing the responses,
So on the file where the ajax is Ive set..
ini_set('ignore_user_abort',true);
and in the function that the ajax calls Ive set...
ini_set('ignore_user_abort',true);   
set_time_limit(0);
For the first one I ran phpinfo() and it did confirm to me that ignore_user_abort was on, meaning obviously that part isnt an issue.
 
    