jedgar Posted February 3, 2009 Share Posted February 3, 2009 Hello, BACKGROUND INFO: I have a script that gets called from a 3rd party software vendor. This vendor is expecting an HTTP 200 status code returned within 10 seconds. The script always runs successfully, and therefore Apache sends the 200 status code back. The issue is that the script will sometimes take longer than 10 seconds to complete, due to large database tables and locking. So even though our web server is sending the 200 code back, it's after the 10 second mark. This causes the 2rd party vendor to resend the request, resulting in duplicate data on our end. QUESTION: Is there a way in php to force a status 200 code to the 'requester', BEFORE the script actually finishes? Meaning, I want to essentially override the web server's duty of sending the code back - or at least tell it not to wait for the script to completely finish. There may even be a configuration setting for sending it back immediately, but I couldn't find any info on that. Thanks in advance for your help! -Joe Quote Link to comment https://forums.phpfreaks.com/topic/143649-can-i-force-an-http-status-code-before-the-script-completes/ Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 You can use exec along with PHP CLI to send the script to a separate process...that way the page "is done" but the process is still running. I am not 100% sure if that would work, but yea. Worth a shot I guess. Quote Link to comment https://forums.phpfreaks.com/topic/143649-can-i-force-an-http-status-code-before-the-script-completes/#findComment-753722 Share on other sites More sharing options...
printf Posted February 3, 2009 Share Posted February 3, 2009 how about... <?php ob_start (); header ( 'Status: 200' ); ob_flush (); flush (); // rest of script here ?> Quote Link to comment https://forums.phpfreaks.com/topic/143649-can-i-force-an-http-status-code-before-the-script-completes/#findComment-753841 Share on other sites More sharing options...
jedgar Posted February 3, 2009 Author Share Posted February 3, 2009 That looks promising, I'll give it a try. Thanks a lot. One question though... After I flush the output buffer, will Apache still send the 200 status back to the requester when the script finishes? Or does ob_start/ob_end_flush cause Apache to not send the status? Thanks again! -Joe Quote Link to comment https://forums.phpfreaks.com/topic/143649-can-i-force-an-http-status-code-before-the-script-completes/#findComment-753883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.