PHP How to send mail in asynchronous mode?
Closed due to the fact that the essence of the question is not clear to the participants dirkgntly , user207618, cheops , D-side , Streletz Aug 26 '16 at 21:23
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
|
1 answer
Create a console command that will send a message. Call it asynchronously using the code below:
/** * Проверяем является ли текущая ос windows * @return bool */ function isWindows(){ return (substr(php_uname(), 0, 7) == "Windows"); } // Путь к входящему файлу для консольных команд $path = 'path/console.php'; // Команда для выполнения $command = '<route> [--option1=value1 --option2=value2 ... argument1 argument2 ...]'; // Собираем все в единое целое $cmd = "php -f {$path} {command}"; if (isWindows()) { // Запускаем под windows pclose(popen("start /b {$cmd}", 'w')); } else { //*nix // Запускаем под linux exec($cmd . " > /dev/null &", $output); }
Addition
A more interesting option can be made using GEARMAN
Hosting Option
It is possible to register sending messages in the database and by cron every 5 minutes call the same console script to send letters without exec and popen
- Does it really work? I just read a lot of different information, but this has never been seen. - gilo1212
- I'm not sure that these commands will work on hosting. for Linux. - gilo1212
- Will work. About hosting is not sure. A more complicated option is to configure this on the Gearman and Supervisor server. - Kison
- Another option with the crown is - Kison
- Slightly updated the answer - Kison
|