Start process after returning to client

Is there a way to continue/start a process after giving a client a result for either a page-request or (pefferably) an API request?

I am trying to setup some sort of websocket system amongst other things which on it’s own works. But I it would be neet if it could be packed in with the Kirby mechanics.

Currently I am starting a separate process (which is highly OS dependend, so not that relayable unfortunately):

$script = "\"namespace my\\namespace; include 'kirby/bootstrap.php'; require '" . __DIR__ . "/EntryPoint.php'; EntryPoint::start(${data});\"";
$logfile = $this->root . static::LOG;

$cmd = "php -r ${script} > ${logfile}";
shell_exec($cmd); // keeps waiting without windows-specific handling
// pclose(popen($cmd, 'r')); // keeps waiting without windows-specific handling

The above code almost work (or at least should work for lunix-based servers), but on windows it keeps hanging without specific handling (like prefixing with start etc.).

So here raises a question of something fundamental:
Is it possible to start a process (which also needs a live Kirby instance btw) after giving the client a response from either a route-callback or an api-callback? The route::after is still called before actually giving the client a response, so that one is not usefull unfortunately.