I have a question about how does php code execute.
I am now only using php to connect to the mysql DB for iOs APP. So I create different APIs at php side. Then, at APP side, just submit post or get request to inquiry or update the DB.
So at php side, I did DB inquiry or update then return a json result to the APP.
Now I have a function, it does the following job:
function a(){
1.Insert a record to the DB;
if (insert successful){
2. $this->echoJson ('Succeed','New Record has added');
3. then send email to several email addresses.(using PHPMailer-master)
}
}
When my APP side get the json data that indicates insertion is successful. The app will jump to another page.
The function works well. The only problem is step 3 takes around 5 seconds to run. Step 1 and 2 is very fast. It seems for the php side, it only returns the json data when all the codes have been executed. So my APP side needs to wait for 5 seconds to get the response. But I only care about if the insertion is successful.
Is it possible to return the json data once the insertion is successful then do the sending?
I am not sure if I explain the problem clearly.
In summary, I found the execution order is step 1 step 3 step 2. I want to make the order as step 1 step 2 step 3.
Thank you.