I read some other question before ask here cause other answers don't response to my problem.
I've a custom made cms in php. For example if I insert a new payment, the script send to all admin user a notify:
function insert_payment() {
// CODE TO INSERT PAYMENT INSIDE MYSQL DB
$sql_payment = "INSERT INTO payments ($amount, ...) VALUES (?, ...);"
...
// NOTIFY ALL ADMINS
foreach ( $array_emails as $email ) {
send_email_to_admin($email, $subject, $body);
}
// redirect to dashboard
header("Location: " . $homepage);
}
This is an example of send_email_to_admin()
function:
function send_email_to_admin($email, $subject, $body) {
// return example:
// $result = array(
// "Error" = true or false
// "DateTimeOfSent" = datetime
// "Email" = string
//)
// SAVE RESULTS IN MYSQL DB ( I need to register results to be sure email are sent without errors...table can be then seen to a specific pages under admin panel of cms)
$mail = new PHPMailer;
...
...
if(!$mail->send()) {
$result = array("Error" => true, "DateTimeOfSent" => date("Y-m-d"), "Email" => $mail);
} else {
$result = array("Error" => false, "DateTimeOfSent" => date("Y-m-d"), "Email" => $mail);
}
$sql_result = "INSERT INTO SentResult ("Error", "DateTimeSent", "Email", ...) VALUES ( $result['Error'], $result['DateTimeOfSent'], $result['Email'] )"
...
//end function
}
Now if I have 1 or 2 admins is ok...but if I have a lot of admins the time gap is not good for waiting a result for each sent.
I'd like to pass the foreach loop to a child process if it possible that can process async the entire loop of SENDING and SAVING inside MYSQL the results.
So header("Location: " . $homepage)
can be executed immediately.
Some additional info:
I'm using hosted server so i can't install packages and libraries
I can use only function provided by default PHP config
I can't use a cronjob queue method cause my hosting not provide a free service
i'd like a solution working on IIS windows server and a Linux based server
I'd like an little script example based on my code cause i never used a async method in php and i don't know nothing about it :(
Sorry for my english