0

I have a PHP script which is run by AJAX. At the end of the script, the server makes an HTTP request to a different server to log the successful completion of the script. The problem is, this second server sometimes takes a while to respond, and I would like this to happen after the AJAX client finishes its request.

Is there some PHP library or similar which could do this? Is my best bet to log the completion to a file on the first server, then have a cron script making the HTTP requests to the second server based on the contents of the file?

JJJollyjim
  • 5,837
  • 19
  • 56
  • 78
  • You are possibly looking got [this](http://stackoverflow.com/questions/12207584/fastest-way-to-fire-and-forget-a-json-post-in-php) – Gargron Feb 16 '13 at 22:16

1 Answers1

0

U can use file_get_contents to call a remote server from your PHP, or use the more complex, but more feature rich CURL wrapper library PHP has.

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
  • I realise that you can use `file_get_contents`, that's what I'm doing at the moment. What I want to do is make the request continue after the first script ends. Can CURL do that? – JJJollyjim Feb 16 '13 at 22:47
  • yes, u do an async equest via cURL (read the doc on how to do it). – Itay Moav -Malimovka Feb 16 '13 at 22:48
  • Sorry, just to clarify, I don't want the request to happen while the rest of the script runs, I want it to run at the end of the script, and continue even though the script isn't running anymore. Is that possible? – JJJollyjim Feb 16 '13 at 23:04
  • yes, My answer was for that. There are other ways, search by my username and async php script or check this http://stackoverflow.com/questions/4380930/how-to-run-a-php-script-asynchronously – Itay Moav -Malimovka Feb 17 '13 at 01:31