I am running my code on CodeIgniter - Ubuntu Server.
I have been researching for async ways to run functions.
This is my function:
As far as I am aware of, you can achieve this in two ways...
Use:
Pthreads is a parallel processing library, while amp is a pure asynchronous framework...
So, the way for using pthreads would be to first download/enable the pthreads extension and add extension=/path/to/pthread.so
in the php.ini file...
And then create a class, which extends the Thread
Class and override the method run, and put everything inside it, which you want to do parallely.
So for your specific purpose the the class could be something like this:
db_con = $db_connection;
$this->data = data;
}
private function run() {
// use your logic to insert the data...
}
}
To use that, just instantiate the class, and put the the DB connection variable, and the data to be processed in the ctor. And call the start method of the object. Like:
$inserter = new Inserter($dbConn, $data);
$inserter->start();
Where $dbConn
stores the DB connection and $data
stores the necessary data.
And that's it...