1

I have a site (site a) that gets requests (from site b) and then returns the number of people, on a per ZIP basis, that meet the qualifications. I've created the request handler on site a to store the request information in the database, and also start the fulfillment of the request.

My problem is this though: the requests can take anywhere from 4 to 5 minutes to complete due to the amount of people in the database (over 300 million). Because of this time, site b is returning timeout issues even though the count fulfillment was still running.

So my question is: Is there a way to trigger a URL request but then not listen for a return?

sdexp
  • 756
  • 4
  • 18
  • 36
Brds
  • 1,035
  • 3
  • 17
  • 37
  • Yup there is. See [this answer](http://stackoverflow.com/a/141026). In the php code, you output some headers to let the client know the connection has been closed, but the php script still continues to execute in the background. – Dave Chen Oct 04 '16 at 21:21
  • 2
    technically all http requests should get a response, but if you don't care about ther esponse, you could just have a timer shut down the request after a specified interval. but if you don't wait for a response, you'll never know if your request was successful, or got stuck at a "waiting for tcp" stage, or whatever. – Marc B Oct 04 '16 at 21:22
  • @MarcB Correct me if I'm wrong, but if you "shut down" the request before it was completed via JavaScript, that will also halt the php execution. I believe the OP wants to allow the client to send some POST data, then allow the client to navigate away, but still allow PHP to finish its processing. – Dave Chen Oct 04 '16 at 21:23
  • 1
    that's why there's [ignore_user_abort()](http://php.net/manual/en/function.ignore-user-abort.php), exactly for when you want the script to keep executing, regardless of the status of the connection that initiated the script. note that the script is STILL subject to the normal time/cpu limits, but at least it won't shut down if the user hits `` or otherwise kills the connection. – Marc B Oct 04 '16 at 21:26
  • Oh I forgot to mention [set_time_limit](http://php.net/manual/en/function.set-time-limit.php). By the way, the answer I linked already describes all of this in great detail. – Dave Chen Oct 04 '16 at 21:32

1 Answers1

0

Sure that is possible:

Use php's cUrl extension for the request, it allows a custom timeout (CURLOPT_CONNECTTIMEOUT) you can set down to maybe 20 seconds. When that timeout expires your script can go on doing whatever it wants without having to bother for any potential reply.

However in general I want to suggest that instead you should try to fix / get fixed the service you are using such that it offers a specific "storage only" access for the exact purpose you describe.

arkascha
  • 41,620
  • 7
  • 58
  • 90