I am running my code on CodeIgniter - Ubuntu Server.
I have been researching for async ways to run functions.
This is my function:
You must mention what's the operating system that you are using, because pcntl extensions are not available on Windows platform
Also you must be aware that activating process control on Linux/Unix within a web server can give you unexpected results, so only CLI/CGI mode is recommended to use PCNTL
Please read carefully this PCNTL Introduction
Now, your code seems to be correct and well implemented, but you must compile your PHP with this option --enable-pcntl
to enable pcntl functions like int pcntl_fork(void)
otherwise you will get
Fatal error: Call to undefined function pcntl_fork()
For me, the best solution to run functions/methods in asynchronous way is to use pthreads, if you are interested by this advice i can edit my response by adding examples and how to install it on Windows or Linux platforms
Read this article to know how to compile PHP