php - SWiFT + TWIG loop different senders -


We have a script that monitors the database. JSON data and senamas and e-mails are stored in the database. If the handled timestamp is zero then the email will still have to be sent. So we have created a chronabage which monitors the column on handling. Email should be sent if it is zero.

Our script works fine, though it is a bit slow, so I was thinking that we are doing it properly.

Receive all emails that should be sent

  foreach ($ result security key as $ key = & gt; $ value) {require_once '../library / Twig / autoloader php '; Twig_Autoloader :: Register (); $ Loader = new Twig_Loader_String (); $ Twig = new Twig_Environment ($ loader, array ('cache' = & gt; '// mp / cache /')); $ Content = $ toggle- & gt; Render (StripSlash ($ templates ['Template HTML']), $ EData; $ Subject = $ twig- & gt; Render ($ Templ ['templateSubject']), $ EData; $ writeFile = FOPAN ( 'Log /' .pdf file .html ',' w '); Fwrite ($ WriteFile, $ content); fclose ($ WriteFile); // Transport $ transport = Swift_SmtpTransport :: newInstance (' mail.example.com ' 25) - & gt; setUsername ('info@example.com ') - & gt; set password (' example password '); // Create a mailer using your built-in transport $ mailer = swift_miler :: new instance ($ Transportation); $ Message = swift_message :: newInstance ($ Subject) -> SetFrom (array ($ resultSoft email [$ key] ['e-mail'] = & gt; $ result selectElex [$ key] ['' '' '' '' '' '' Settone ($ contents, 'text / html', 'UTF-8'); -> Setto (array (Select $ result email [$ key] ['tomail'])) -> (Isset ($ EmailAttachements)) {foreach ($ EmailAttachements AS $ key = & gt; $ value) $ message- & gt; Attached (Swift_Attachment :: fromPath ($ value)); } $ Result = $ Mailer- & gt; Send ($ message); }  

In the script we create a separate transport for each email. Sometimes the mail server throws an error. Mainly this can not be logged in

Can we improve the performance of the script?

Looking forward to your thoughts ....

I have seen some calls Are giving you, which you should not do in the Freshcha Loop. I do not know how many mails you want to send, but it is not optimal as you are not processing the loop in parallel, you can move some rows, preventing some instances from making repeated. I do not know the exact purpose of your code and it is difficult to say without any details that this is a significant improvement, but you can try it:

  need_once '../library/ Twig / Autoloader.php '; Twig_Autoloader :: Register (); $ Loader = new Twig_Loader_String (); $ Twig = new Twig_Environment ($ loader, array ('cache' = & gt; '// mp / cache /')); // Transport $ transport = Swift_SmtpTransport :: newInstance ('mail.example.com', 25) - & gt; SetUsername ('info@example.com ') - & gt; Set password ('example password'); // Create a mailer using your built-in Transport $ Mailer = SWIFT_Amler :: New instance ($ transport); Forex Currency ($ ResultSelectEmails AS $ key = & gt; $ value) {$ content = $ twig- & gt; Submit (stripsash ($ Templ ['templateHTML']), $ EData; $ Subject = $ twig- & gt; Render ($ Templ ['templateSubject']), $ EData; $ writeFile = fopen ('log / '. $ PDFLogFile.' .html ',' w '); Fwrite ($ WriteFile, $ content); fclose ($ WriteFile); $ Message = swift_message :: newInstance ($ theme) - & gt; setFrom (array ($ Results: [['' '' '' '' '' '' '' '' '' '' '') '- [' '$'] ['e-mail'] => Select the result $ [['' '' '' '' '' ']) - & gt; Setto (array Select $ resultemail [$ key] ['tomail'])) - & gt; SetBody ($ content, 'text / html', 'UTF-8'); if (isset ($ EmailAttachements)) {foreach ($ EmailAttachements AS $ key = & gt; $ value) $ message- & gt; NO Mental worries (Swift_Attachment :: fromPath ($ value));} $ result = $ Melr- & gt; send ($ message);}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -