I am developing automated bulk sending emails portal in PHP CodeIgniter 3, and its hosted on AWS just like Lemlist https://www.lemlist.com/ or Woodpecker https://woodpecker.co/. It send bulk emails in a loop (Email Campaign). Everything works fine up till here.
Now the problem is whenever I execute a campaign, it starts sending emails as per my code in a loop but after sending 6 to 7 emails I do not know how but it executes the same process parallel which starts sending email from start, though there is nothing in code to duplicate process or anything related to this. I wrote email delivery status in backlog file for test, so I discovered this issue.
For example, I started a campaign which has 20 emails. So when it sends 6 to 7 emails, now it starts sending emails from 1 in another process and continues the existing process in parallel.
Please see my backlog file in the attachment
So in my backlog file, I get status like below
email1@example.com SENT TOTAL EMAILS SENT 1
email2@example.com SENT TOTAL EMAILS SENT 2
email3@example.com SENT TOTAL EMAILS SENT 3
email4@example.com SENT TOTAL EMAILS SENT 4
email5@example.com SENT TOTAL EMAILS SENT 5
email6@example.com SENT TOTAL EMAILS SENT 6
email7@example.com SENT TOTAL EMAILS SENT 7
email1@example.com SENT TOTAL EMAILS SENT 1 <!-- PROCESS REPLICATED IT SELF & STARTED THE SAME LOOP -->
email8@example.com SENT TOTAL EMAILS SENT 8 <!-- OLD PROCESS THAT WE ACTUALLY EXECUTED IS ALSO BEING EXECUTED -->
email2@example.com SENT TOTAL EMAILS SENT 2 <!-- THIS IS SENT BY REPLICATED PROCESS -->
email9@example.com SENT TOTAL EMAILS SENT 9 <!-- THIS IS STILL BEING SENT BY OLD/REAL PROCESS -->
email3@example.com SENT TOTAL EMAILS SENT 3
email10@example.com SENT TOTAL EMAILS SENT 10
Up to So on....
I need a solution to fix this. Also I want to know how can I control this process in PHP, so that when I want to kill or pause this process, I can do it from a button in my form.