There is no "Drupal 8 way." Drupal 8 relies on Guzzle as its HTTP client library so it doesn't have a built-in solution for this.
While the Guzzle client library has GuzzleHttp\Client::requestAsync()
, it's not a non-blocking asynchronous method; the method will block once it has initiated the network request since it needs response data for promise methods.
In order to do something akin to your linked question (using fsockopen()
/ fwrite()
to open a socket, send HTTP headers, & close) with Guzzle, you'll need to use a different handler than the default ones Guzzle provides. Guzzle has some documentation on to do this.
It should be noted, even the linked solution isn't non-blocking in the event there are network connection issues (e.g. if the host is unreachable, fsockopen()
has $timeout
set to 30
, so it would block for 30s before timeout was hit). PHP being single-threaded prevents true non-blocking asynchronous execution within PHP code.