缓慢的php进程
我有一个关于调用一个函数的问题,这个函数需要很长时间,我希望一些人能看到我是否做了一些违法的事情 当我从sendletter.php在下面的函数中运行GetEmailCue时,大约需要一分钟左右的时间才能完成,我不知道为什么 emailcue db表仅包含2封电子邮件缓慢的php进程,php,mysql,performance,function,process,Php,Mysql,Performance,Function,Process,我有一个关于调用一个函数的问题,这个函数需要很长时间,我希望一些人能看到我是否做了一些违法的事情 当我从sendletter.php在下面的函数中运行GetEmailCue时,大约需要一分钟左右的时间才能完成,我不知道为什么 emailcue db表仅包含2封电子邮件 /****************************************** * Sends a letter from the email cue *
/******************************************
* 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);
}
}
此函数从另外两个函数中提取数据
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;
}
及
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;
}
我在我的Ubuntu本地主机上运行它发送电子邮件需要一些时间,但你说,只发送了两封邮件。这并不多 此代码是否在任何电子邮件行上进行更新
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);
}
您是否尝试使用microtime功能测量单个代码部分的运行时间?发送电子邮件需要一些时间,但您说,只发送了两封邮件。这并不多 此代码是否在任何电子邮件行上进行更新
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);
}
您是否尝试使用microtime功能测量单个代码部分的运行时间?当发送电子邮件时,该电子邮件将获得时间戳,以避免他/她多次收到新闻稿。foreach更新了刚刚发送的电子邮件。。。我可以尝试测量运行时间。$cue->GetEmailCue($letter_id)在SendTheLetter中的运行时间为0.00030803680419922,而foreach的运行时间为60.888072013855-这看起来很疯狂!感谢您提供有关运行时的提示。。看来我已经把问题隔离出来了,邮件功能。。。这可能是Ubuntu localhost中的设置吗?很抱歉我的回答太晚(我是@work),我想这可能是邮件服务器本身。也许可以尝试测量邮件->提交的时间。我的ErrorHandler函数也发送电子邮件,并且总是需要一定的时间来完成。我不知道您使用的是哪种邮件类,但也许您可以选择将电子邮件排队并一次发送所有邮件。
foreach($cue->email\u行为$key=>$value)
$value有什么值?这是一个id吗?AFAIK的问题是Ubuntu内部的sendmail,它有大约60秒的延迟,根据mail上的运行时,这似乎是正确的。。。或者域名和DNS等。我用apt get install安装了sendemail,然后再次运行脚本,它马上就完成了!:)我已经接受了你的回答,因为你给了我关于运行时间的提示,这让我想到了邮件功能!因此,谢谢:)当发送电子邮件时,该电子邮件将获得时间戳,以避免他/她多次收到新闻稿。foreach更新了刚刚发送的电子邮件。。。我可以尝试测量运行时间。$cue->GetEmailCue($letter_id)在SendTheLetter中的运行时间为0.00030803680419922,而foreach的运行时间为60.888072013855-这看起来很疯狂!感谢您提供有关运行时的提示。。看来我已经把问题隔离出来了,邮件功能。。。这可能是Ubuntu localhost中的设置吗?很抱歉我的回答太晚(我是@work),我想这可能是邮件服务器本身。也许可以尝试测量邮件->提交的时间。我的ErrorHandler函数也发送电子邮件,并且总是需要一定的时间来完成。我不知道您使用的是哪种邮件类,但也许您可以选择将电子邮件排队并一次发送所有邮件。foreach($cue->email\u行为$key=>$value)
$value有什么值?这是一个id吗?AFAIK的问题是Ubuntu内部的sendmail,它有大约60秒的延迟,根据mail上的运行时,这似乎是正确的。。。或者域名和DNS等。我用apt get install安装了sendemail,然后再次运行脚本,它马上就完成了!:)我已经接受了你的回答,因为你给了我关于运行时间的提示,这让我想到了邮件功能!所以谢谢你:)