PHP CodeIgniter Email Delay

First of all, I would like to thank StackOVerflow and its users for their help in solving a number of technical problems. I created this account today, since I could not see how the problem would be fixed.

Problem . I had a problem sending emails to PHP CodeIgniter. The $ this-> email-> send () function takes about 3-4 seconds each time to execute.

We have a social platform where users come and publish things. Every time a user downloads a new update, we want to send him an email. The problem is that the email sending function takes about 3-4 seconds, and we would like to reduce it to 1 second.

Is there a way we can do the email sending process in parallel? Let's say python code that runs continuously to receive new updates and send emails to these users. Any better method?

Technological stack - PHP CI, MySQL, Apache, Windows

This is the email code that gets called with every new update -

$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'smtp.gmail.com', 'smtp_port' => 587, 'smtp_user' => ' mailid@gmail.com ', 'smtp_pass' => 'password', 'mailtype' => 'html', 'charset' => 'utf-8', 'smtp_crypto' => "tls" ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->set_mailtype("html"); $this->email->from(' mailid@gmail.com ', 'Support'); $this->email->to($this->session->userdata['email']); $this->email->subject('You have posted a new update'); $this->email->message('Please login to check your new update. Do not reply to this email. For any issues reach out to email@emailid.com '); if (!$this->email->send()) { show_error($this->email->print_debugger()); } else { echo true; } 
+5
source share
2 answers

His suggestion is to store email in a databse and send these emails using a job. therefore, the user’s download should not wait for sending emails at a time.

If you need code to set cron and smtp mailer , just comment on ans

+1
source

If your function is faster, but sending emails is slower, this should be a problem for your smtp connection. Either your server connects to SMTP not much faster, or SMTP, which you use a bit slower to respond. In this case, try using the gmail SMTP server and see the result.

+1
source

Source: https://habr.com/ru/post/1271895/


All Articles