I have the following dilemma, I have a SOAP API, need to optimise a method:
public function myMethodForOptimisation(array $options) {
//doing some stuff
$this->requestsAnUltraSlowTimeConsumingMethod();
return $someData;
}
I do not really need to wait for the finalisation of the $this->requestsAnUltraSlowTimeConsumingMethod()
i just asynchronously want to say to this method to do stuff and return
the result to customer.
Need to transform it in something like:
public function myMethodForOptimisation(array $options) {
//doing some stuff
async_method_call($this->requestsAnUltraSlowTimeConsumingMethod());
return $someData;
}
Is there an async_method_call() in PHP ?
You cannot execute a method asynchronously. But you could return the data to the client, close the connection, and execute your time consuming method once you disconnected.
Another solution to execute php code asynchronously is forking a new process with pclose(popen()).
Or for a really advanced solution you could look into the threading module of PHP.
You may use threads: PHP threading call to a php function asynchronously
This is quite only way to do so. there is several ways of using them, so choice the best/easiest for you.
Im using this normally: http://php.net/manual/en/class.thread.php