This is a weird problem and I can't figure out what is going wrong:
I have got a script that is scheduled to run every couple of days. It is actually not cron, but a scheduled task (php file) that is run by IIS.
The php file is emailing a list of users (about 5,000) individual information according to their personal settings. In fact what we send them out are descriptions of jobs that were posted in the current week that match their profile.
The script seems to run fine and email all the appropriate users. But it does not send out all the jobs it should. So let's say a user should receive information on 38 jobs - only 19 are being emailed to him.
Almost sounds as if the SQL statement that selects the jobs is incorrect, right? Wrong. It only happens if I execute the script for all 5000 users. If I reduce the user amount to 10, it sends out the correct amount of jobs for each user.
So to me it seems as if the success of the SQL statement depends on the length the script takes to execute. Does that sound right? Did anybody experience something like that before?
The script takes about half an hour to execute completely, so it's quite busy working away. Does anybody have an idea of where I go wrong?
Here is a rough breakdown of what it does:
- get all Jobseekers that receive emails
- loop through all selected users
- Find jobs for current user
- if new jobs are available for this user, prepare the email
- loop through all jobs for current user
- write current job into email message
- send the email
You think it would be useful to post the code?