in reply to Looping through database query to send emails is taking too long

10 seconds is far too long for a database lookup on 100 records. It also sounds like too long to send a modest number of emails. Have you tried running the script off line to check that it really takes as long as you are reporting?

If the script does take as long as reported you should put together a sample script (see I know what I mean. Why don't you? for some hints) and we'll help speed it up for you.

If it turns out that the processing time is unavoidable you can always fork off a task to send the emails and complete the http transaction without waiting. See replies to Managing a long running server side process using CGI for ways to do that.

Premature optimization is the root of all job security
  • Comment on Re: Looping through database query to send emails is taking too long

Replies are listed 'Best First'.
Re^2: Looping through database query to send emails is taking too long
by afoken (Chancellor) on Jul 21, 2015 at 08:30 UTC
    10 seconds is far too long for a database lookup on 100 records.

    Yes. Maybe missing indexes or missing primary key? htmanning, please show the select statement and the table definition(s) (create statements).

    Another problem may be the mailserver. Internal mail servers are usually very generous, unlike public mail servers. On the latter ones, intentional delays are quite usual to defend against spam bots. The usual way around this problem is to talk with the mail server admin, (s)he will know which mailserver to use, and how to login there, if needed.

    Adding some debug output with timestamps to the program should show very fast which part of the program is slow.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)