I’m attempting to do an AJAX call (via JQuery) that will initiate a fairly long process. I’d like the script to simply send a response indicating that the process has started, but JQuery won’t return the response until the PHP script is done running.
I’ve tried this with a ‘close’ header (below), and also with output buffering; neither seems to work. Any guesses? or is this something I need to do in JQuery?
<?php echo( 'We'll email you as soon as this is done.' ); header( 'Connection: Close' ); // do some stuff that will take a while mail( 'dude@thatplace.com', 'okay I'm done', 'Yup, all done.' ); ?>
The following PHP manual page (incl. user-notes) suggests multiple instructions on how to close the TCP connection to the browser without ending the PHP script:
Supposedly it requires a bit more than sending a close header.
OP then confirms: yup, this did the trick: pointing to user-note #71172 (Nov 2006) copied here:
Later on in July 2010 in a related answer Arctic Fire then linked two further user-notes that were-follow-ups to the one above: