PHP Classes

Can you example ?

Recommend this page to a friend!

      Simple PHP Multithreading  >  All threads  >  Can you example ?  >  (Un) Subscribe thread alerts  
Subject:Can you example ?
Summary:Can you example ?
Messages:3
Author:BratSadLove
Date:2020-05-15 12:34:20
 

  1. Can you example ?   Reply   Report abuse  
BratSadLove - 2020-05-15 12:34:20
Hi guy !

Thanks for this class but can you write small example ?


  2. Re: Can you example ?   Reply   Report abuse  
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 :)

  3. Re: Can you example ?   Reply   Report abuse  
Mahesh S - 2020-05-15 14:40:57 - In reply to message 2 from Mahesh S
Sorry, one correction to the usage example given in the previous message:

It is to be used like:

$threader = new \cs\simplemultithreader\Threader(['arguments' => ['mailerObject' => $mailerObect, 'mail' => $mail]]);
$jobId = $threader->thread(function($arguments){
$arguments['mailerObject']->sendMail($arguments['mail']);
});

 

For more information send a message to info at phpclasses dot org.