Jump to content

Can I force an HTTP Status Code before the script completes?


Recommended Posts

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

 

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.