Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:21:59+00:00 2026-05-27T14:21:59+00:00

I have a question regarding a call to a function that takes quite a

  • 0

I have a question regarding a call to a function that takes quite a while and I hope some can see if I did something criminal.

When I run the function GetEmailCue in the function below from sendletter.php it takes a about a minute or so to complete and I can’t figure out why.

The emailcue db table only contain 2 emails.

         /******************************************
         * Sends a letter from the email cue
         * 
         * @param int       | The letter id
         *******************************************/
        function SendTheLetter($letter_id) {

            /*** Find the email cue based on the newsletter uid ***/
            $cue = new NewsletterHandler;
            $cue->GetLetterContent($letter_id);
            $cue->GetEmailCue($letter_id);

            $headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

            foreach($cue->email_row as $key => $value) { 
                mail($value, "Newsletter - ". date("d-m-Y"), $this->htmlTemplate, $headers);
                $sql_update = "UPDATE newsletter_emailcue SET time_recieved = NOW() WHERE email = '". $value ."'";
                SQLHandling::SQLquery($sql_update);                
            }
        }   

This functions pull data from two other functions

GetLetterContent:

         /******************************************
         * Find all fields that belongs to a    
         * newsletter.
         * 
         * @param int       | The letter id
         *******************************************/
        function GetLetterContent($letter_id) { 

            $sql = "SELECT A.template, A.status, B.field_name, B.field_content FROM newsletter_items A, newsletter_fields B WHERE B.field_letter_uid = '". $letter_id ."'";           

            $result = SQLHandling::SQLquery($sql);

                while($row = mysql_fetch_array($result)) { 

                    $this->content_markers["". $row["field_name"] .""] = $row["field_content"];
                    $template = $row["template"];
                }

                /*** Compile the letter with all the markers ***/
                $this->CompileLetter($letter_id, $template, $this->content_markers);
                return;                
        }

and

GetEmailCue:

         /******************************************
         * Get an entire email cue based on a 
         * newsletter id.
         * This functions is called from the send 
         * function.
         * 
         * @param int       | The letter id
         *******************************************/
        function GetEmailCue($letter_id) {
            $sql = "SELECT * FROM newsletter_emailcue WHERE mail_to_recieve = '". $letter_id ."' AND time_recieved = '0000-00-00 00:00:00' LIMIT 1";
            $result = SQLHandling::SQLquery($sql);

            if(mysql_num_rows($result) < 1) {
                $sql_update = "UPDATE newsletter_items SET status = 2 WHERE letter_id = '". $letter_id ."'";
                SQLHandling::SQLquery($sql_update);
            } else {              
                while($row = mysql_fetch_array($result)) {
                    $this->email_row[] = $row["email"];
                }
            }

            return $this->email_row;
        }

It seems that GetEmailCue might be the issue, because if I comment it out in SendTheLetter the function is executed right away and if I run GetEmailCue directly from a file this function is also executed right away, but when I run it within SendTheLetter it takes for ever.

SendTheLetter function is again called from FindLetterToSend

         /******************************************
         * Finds all letters that have send status 1
         * which is pending to send.
         *******************************************/
        function FindLetterToSend() { 
            $sql = "SELECT * FROM newsletter_items WHERE status = '1'";           
            $result = SQLHandling::SQLquery($sql);

            if(mysql_num_rows($result) == 0) { 
               Main::txtOutput("Der er ingen nyhedsbreve i udsendelseskøen!", "TXT_ERR");               

               /*** Let's clear the emailcue table - no need for the cue any more ***/
               SQLHandling::SQLquery("TRUNCATE TABLE newsletter_emailcue");               
            } else {
                while($row = mysql_fetch_array($result)) { 
                    $this->SendTheLetter($row["letter_id"]);
                }
            }
            return;
        }

I am running it on my Ubuntu localhost

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:21:59+00:00Added an answer on May 27, 2026 at 2:21 pm

    Sending E-Mails takes some time, but you said, that only two mails have been sent. This isn’t much.

    This code does an update on any email-line?

    foreach($cue->email_row as $key => $value) { 
        mail($value, "Newsletter - ". date("d-m-Y"), $this->htmlTemplate, $headers);
        $sql_update = "UPDATE newsletter_emailcue SET time_recieved = NOW() WHERE email = '". $value ."'";
        SQLHandling::SQLquery($sql_update);                
    }
    

    Did you try to measure the runtime of the single code-parts with microtime function?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding static function in php. let's assume that I have
bit of noob question regarding .Net and C#. I have a function that registers
My question is regarding JavaScript Closures and the Eval() function. I have some code
I have couple questions regarding some C++ rules. Why am I able to call
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding jQuery. I have multiple images that are, in essence,
I have a question regarding performance. Is there a performance penalty when I call
I have a question regarding this article. Between this code function odds(n, p) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.