Mahesh S - 2020-05-15 14:03:36 -
In reply to message 1 from BratSadLove
Hi BradSadLove
Suppose you have a time consuming task to be done(like sending emails to 100,000 member of your website) but you don't want the current request to wait until the mail sending script is finished.
So suppose the below line of code sends the message to all member:
$mailerObject->sendMail($mail); //takes about say 10 mins to finish processing
If you put this in your main script, the request sent to the webserver won't be finished until 10 mins because the above code is in the main thread.
You can make this line of code to be processed parallelly in the background by using my class as below:
$threader = new \cs\simplemultithreader\Threader(['arguments' => ['mailerObject' => $mailerObect, 'mail' => $mail]]);
$jobId = $threader->thread(function($arguments){
$mailerObject->sendMail($mail);
});
So by using like this, the request won't wait for the mail sending to be finished and will get finished instantly.
Hope you understood the example. Please don't hesitate to ask if you want more clarification.
Please leave a star at https://github.com/codespede/simple-multi-threader if you like the class :)