I have a small ordering taking app which submits the order to a PHP script by ajax. When the PHP script receives the order it places it in a database, sends an 'OK' message back to the client and then sends a confirmation email to the customer and another to me. The problem is that the client is not seeing the 'OK' (which updates the browser display) for about 15 seconds. If I comment out the email sends, no delay.
... write to database
echo "OK";
mail($semail,'Msg Subject',$message, $header, $bounceto);
mail($semail2,'Msg Subject',$mesage, $header, $bounceto);
Message is only a couple of lines.
Questions:
- why would there be a delay when calling the mail() function?
- how can I cause the 'OK' message to be sent without waiting for the PHP script to complete? A flush of some sort I'm guessing.