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

it takes about 10 seconds or longer

That doesn't seem to be such a long time to ask your users to wait?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
  • 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 htmanning (Friar) on Jul 21, 2015 at 05:49 UTC
    I wouldn't mind them waiting if I could provide a "please wait" or appropriate graphic. When they click SEND, the script takes 10 seconds to cycle through the database.

    It's a MYSQL database with maybe 100 records. The script loops through and sends an email to records that have notifications set to yes

    BTW, I just thought of something. Maybe my code is off. I have 2 email fields in each database records, (email, email2). Each email field can have a notification set or not. I'm looping through twice, maybe that's the problem.

    $SQL = "select * from $resident_info_table where email!='' and email_a +lert = 'yes' order by ID desc"; &Do_SQL; while ($pointer=$sth->fetchrow_hashref) { $recipient = $pointer->{'email'}; &send_email; } $SQL2 = "select * from $resident_info_table where email2!='' and email +2_alert = 'yes' order by ID desc"; &Do_SQL2; while ($pointer2=$sth2->fetchrow_hashref) { $recipient = $pointer2->{'email'}; &send_email; }

    Is there a way to do both queries in one sql search?

      I wouldn't mind them waiting if I could provide a "please wait" or appropriate graphic. When they click SEND,

      Why not add:

      [SEND] Note: this will take upto 30 seconds. Please be patient.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

      Hmmm, then you can show some progress bar on your web application, after user clicks SEND button.


      All is well. I learn by answering your questions...
        I do have a note asking them to be patient, but I'd like a please wait screen to show while the sending is happening. Right now, even though I have the print line for the "please wait" before the actual loop, the browser doesn't show it until the messages are sent. It flashes briefly before the confirmation screen is shown. It defeats the purpose of it.