I have an email list of people I have to send out emails to every morning. The number is about 1000 at the moment and it is on my own VPS LINUX server.
The problem is that when the job is running the websites I have on the server seem to hang and timeout quite a lot.
I thought adding a sleep command of a couple of seconds between each iteration of the loop would help this but a PHP developer at my work just told me that this wouldn't do anything to help Apache in regards to memory and it would be better to just run the script without any sleep command.
I have read articles on here and other sites where people recommend adding a sleep command in between the loop iterations but if this just means that the Apache process consumes more memory and causes my site to hang then I don't want that to happen.
I am calling this job from my domain from a CRON job with a secure hash. The reason I am calling it externally through my site e.g http://www.example.com/sendemails.php?secretcode=_--1033-449 is that often I need to debug it to see what is going on or if the job hasn't run I can run it manually and read the debug on the page.
Is there an issue with Sleep and Apache / website timeouts or should I do it in another way e.g having some sort of batch of starting the script every 10 minutes and sending out 100 emails before updating a flag in the DB against the person so I know they have had an email sent (True/False) and starting from that point in the next batch.
Then at night after a certain time e.g 6pm when I know no emails should be sent out I could easily re-set all their flags to False ready for tomorrow. Ensuring no emails are sent after 6pm of course.
What is the preferred way of doing things like this as it does seem that the website hangs/times out during the time the job runs.
Thanks
Rob