D
D
Decker2015-11-18 21:59:24
PHP
Decker, 2015-11-18 21:59:24

Sending a mail message in PHP in a separate "thread". Implementation methods?

The question has probably already been ridden more than once, and judging by the title, everyone will think "well, again." But in fact, it is not about how to send a mail message in PHP, you can use mail, you can use phpmailer, there are a lot of ways. Question about something else. Let's say we have an abstract function send_message(...) inside which sending email is implemented in one way or another. What is the best way to do it in a separate "thread" (the thread is not in quotation marks for nothing, because PHP does not support multithreading). Suppose we have a script like:

<?php
echo "Begin ... \r\n";
send_message(...);
echo "End ... \r\n";
?>

When executing the script, for example, in the case when the STMP server through which the sending occurs is unavailable or in case of any other delays in the execution of send_message(...), the time difference between the display of Begin and End will be significant. What is the best way to implement sending so that send_message(...) is executed in the "background" or as quickly as possible without slowing down the execution of the main script? In other words, I want the script to complete successfully and as quickly as possible, regardless of the time for which send_message (...) will work.
psFor myself, while I see the simplest option - with the optimization of all checks inside send_message(...) ... i.e. Resolving the SMTP server name is not available - we interrupt the execution of the function, SMTP is not available - we also interrupt the sending, etc. The emphasis is not on guaranteed message sending, but on completing the execution of the main script in a fixed time.
Suggestions / wishes, etc. can be introduced in the form of ideas, without specific implementation. Those. the direction "where to dig" is enough.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sunrails, 2015-11-18
@sunrails

Everything can be made easier :)
ruhighload.com/index.php/2009/05/15/%D0%BE%D1%87%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question