Let’s say that there are two PHP functions.
function first()
{
$keyword = $this->input->post('keyword');
//search for the result and show it to users.
$this->search->search($keyword);
//send the keyword to save it into the db.
$this->second($keyword);
}
function second($keyword)
{
//saving a search keyword in the db
}
I would like to send the result as soon as possible and save the search word into DB.
However, I want to run the second script later after specific time.
because I want to deliver the search result as soon as possible to my customer.
Is there a way to run second PHP script after a user run the first PHP script?
* I don't want to use Cron Job
* I wanna run those two script separatly.
* don't want to use sleep because it will stop the first script for certain times.
You’ll need to route it back round to your server, but this asynchronous php approach works quite nicely (I’ve been using it for about a year to do almost exactly what you seem to be doing).
See: How to run the PHP code asynchronous