Is there a way in PHP to make HTTP calls and not wait for a response? I don’t care about the response, I just want to do something like file_get_contents(), but not wait for the request to finish before executing the rest of my code. This would be super useful for setting off "events" of a sort in my application, or triggering long processes.
Any ideas?
You can do trickery by using exec() to invoke something that can do HTTP requests, like
wget, but you must direct all output from the program to somewhere, like a file or /dev/null, otherwise the PHP process will wait for that output.If you want to separate the process from the apache thread entirely, try something like (I’m not sure about this, but I hope you get the idea):
It’s not a nice business, and you’ll probably want something like a cron job invoking a heartbeat script which polls an actual database event queue to do real asynchronous events.