Asynchronous PHP function can be make via message queue. It is easy to make a message queue based on Redis or MongoDB. And there are also many message queue libraries to select. But for the lite widght process finishing in several seconds, there is a simper way to do this. Fork a background process to do the long time job and return immeditally.
In the web page, call the background process like this:
$job_id = time(); shell exec("php job.php PASSWORD '".$job_id."' >> job.log &"); echo 'Job received.';
In the job processing script:
if($argv !='PASSWORD') return; sleep(10); echo 'Done.';