PHP与Smtp的通信

PHP与Smtp的通信,php,email,cron,Php,Email,Cron,我有一个邮件应用程序,每天通过cron-job发送大约5000封电子邮件(大量的帐户文书工作),当邮件只发送给一个收件人时,工作正常问题出现在我们激活密件抄送副本时,然后应用程序开始发送邮件,直到980-1050封,并开始从smtp接收4.5.3错误(收件人太多)。如果我暂停作业并再次运行cron,php进程将获得一个新的pid,并开始发送ok,直到达到相同的限制(980-1050封邮件) 所以我的问题是:有没有办法重新生成php进程id? 如果我能够做到这一点,那么应用程序将毫无问题地发送这些

我有一个邮件应用程序,每天通过cron-job发送大约5000封电子邮件(大量的帐户文书工作),当邮件只发送给一个收件人时,工作正常问题出现在我们激活密件抄送副本时,然后应用程序开始发送邮件,直到980-1050封,并开始从smtp接收
4.5.3
错误(收件人太多)。如果我暂停作业并再次运行cron,php进程将获得一个新的pid,并开始发送ok,直到达到相同的限制(980-1050封邮件)

所以我的问题是:有没有办法重新生成php进程id?

如果我能够做到这一点,那么应用程序将毫无问题地发送这些邮件

或者我缺少一些后缀配置?

守则的有关部分:

/**
* _Send_SmtpData
* Handles the SMTP negotiation for sending the email header and body.
*
* @param String $rcpt_to The 'receipt to' address to send the email to. This is a bare email address only.
* @param String $to The 'to' address to send this to. This can contain a name / email address in the standard format ("Name" <email@address>)
* @param String $subject The subject of the email to send.
* @param String $body The body of the email to send.
* @param String $headers The headers of the email to send.
**/ 

function _Send_SmtpData(&$rcpt_to, &$to, &$subject, &$body, &$headers)
{

    $data = "DATA";

    $this->DebugMemUsage('Trying to put ' . $data);

    if (!$this->_Put_Smtp_Connection($data)) {
        $this->ErrorCode = 12;
        $this->ErrorCodeSMTPEnhanced = false;
        $this->Error = GetLang('UnableToSendEmail_Data');
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $response = $this->_get_response();

    $this->DebugMemUsage('Got response ' . $response);

    $responsecode = substr($response, 0, 3);

    if ($responsecode != '354') {
        $this->ErrorCode = $responsecode;
        $this->ErrorCodeSMTPEnhanced = $this->_GetSMTPEnhancedErrorCode($response);
        $this->Error = $response;
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $msg = "To: " . $to . $this->_smtp_newline . "Subject: " . $subject . $this->_smtp_newline . $headers . $this->_smtp_newline . preg_replace('/^\.(\r|\n)/m', ' .${1}', $body);

    $msg = str_replace("\r\n","\n",$msg);
    $msg = str_replace("\r","\n",$msg);
    $lines = explode("\n",$msg);
    foreach ($lines as $no => $line) {
        // we need to rtrim here so we don't get rid of tabs before the start of the line.
        // the tab is extremely important for boundaries (eg sending multipart + attachment)
        // so it needs to stay.
        $data = rtrim($line);

        $this->DebugMemUsage('Trying to put ' . $data);

        if (!$this->_Put_Smtp_Connection($data)) {
            $this->ErrorCode = 13;
            $this->ErrorCodeSMTPEnhanced = false;
            $this->Error = GetLang('UnableToSendEmail_DataWriting');
            $this->_Close_Smtp_Connection();

            $this->DebugMemUsage('Got error ' . $this->Error);

            return array(false, $this->Error);
        }
    }

    $data = $this->_smtp_newline . ".";

    $this->DebugMemUsage('Trying to put ' . $data);

    if (!$this->_Put_Smtp_Connection($data)) {
        $this->ErrorCode = 14;
        $this->ErrorCodeSMTPEnhanced = false;
        $this->Error = GetLang('UnableToSendEmail_DataFinished');
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $response = $this->_get_response();

    $this->DebugMemUsage('Got response ' . $response);

    $responsecode = substr($response, 0, 3);
    if ($responsecode != '250') {
        $this->ErrorCodeSMTPEnhanced = $this->_GetSMTPEnhancedErrorCode($response);
        $this->ErrorCode = $responsecode;
        $this->Error = $response;
        $this->_Close_Smtp_Connection();

        $this->DebugMemUsage('Got error ' . $this->Error);

        return array(false, $this->Error);
    }

    $this->DebugMemUsage('Mail accepted ');

    /**
     * We got this far, this means we didn't encounter any errors.
     * Cleanup previous error codes and variables since they are no longer relevant
     * with the current process iteration.
     */
    $this->Error = '';
    $this->ErrorCode = false;
    $this->ErrorCodeSMTPEnhanced = false;

    $this->_smtp_email_count++;
    return array(true, false);
}
/**
*\u发送\u SmtpData
*处理发送电子邮件头和正文的SMTP协商。
*
*@param String$rcpt_发送电子邮件至“收件人”地址。这只是一个简单的电子邮件地址。
*@param String$将其发送到“收件人”地址。它可以包含标准格式的名称/电子邮件地址(“名称”)
*@param String$subject要发送的电子邮件的主题。
*@param String$body要发送的电子邮件的正文。
*@param String$headers要发送的电子邮件的标题。
**/ 
函数发送SmtpData(&$rcpt_至、&$to、&$subject、&$body、&$headers)
{
$data=“data”;
$this->DebugMemUsage('试图放置'.$data');
如果(!$this->\u Put\u Smtp\u连接($data)){
$this->ErrorCode=12;
$this->errorcodesmtprecensed=false;
$this->Error=GetLang('unabletosendmail_Data');
$this->_Close_Smtp_Connection();
$this->DebugMemUsage('Got error'.$this->error);
返回数组(false,$this->错误);
}
$response=$this->_get_response();
$this->DebugMemUsage('Got response'.$response);
$responsecode=substr($response,0,3);
如果($responsecode!=“354”){
$this->ErrorCode=$responsecode;
$this->errorcodesmtprecensed=$this->\u GetSMTPEnhancedErrorCode($response);
$this->Error=$response;
$this->_Close_Smtp_Connection();
$this->DebugMemUsage('Got error'.$this->error);
返回数组(false,$this->错误);
}
$msg=“To:”..$To.$this->\u smtp\u newline.“Subject:”..$Subject.$this->\u smtp\u newline.$headers.$this->\u smtp\u newline.preg\u replace('/^\.(\r |\n)/m','.${1}',$body);
$msg=str\u replace(“\r\n”、“\n”、$msg);
$msg=str\u replace(“\r”、“\n”、$msg);
$lines=explode(“\n”,$msg);
foreach($no=>$line的行){
//我们需要在这里进行rtrim,这样我们就不会在开始生产线之前去掉制表符。
//该选项卡对于边界非常重要(例如发送多部分+附件)
//所以它需要留下来。
$data=rtrim($line);
$this->DebugMemUsage('试图放置'.$data');
如果(!$this->\u Put\u Smtp\u连接($data)){
$this->ErrorCode=13;
$this->errorcodesmtprecensed=false;
$this->Error=GetLang('unabletosendmail_DataWriting');
$this->_Close_Smtp_Connection();
$this->DebugMemUsage('Got error'.$this->error);
返回数组(false,$this->错误);
}
}
$data=$this->_smtp_newline.“;
$this->DebugMemUsage('试图放置'.$data');
如果(!$this->\u Put\u Smtp\u连接($data)){
$this->ErrorCode=14;
$this->errorcodesmtprecensed=false;
$this->Error=GetLang('unabletosendmail_DataFinished');
$this->_Close_Smtp_Connection();
$this->DebugMemUsage('Got error'.$this->error);
返回数组(false,$this->错误);
}
$response=$this->_get_response();
$this->DebugMemUsage('Got response'.$response);
$responsecode=substr($response,0,3);
如果($responsecode!=“250”){
$this->errorcodesmtprecensed=$this->\u GetSMTPEnhancedErrorCode($response);
$this->ErrorCode=$responsecode;
$this->Error=$response;
$this->_Close_Smtp_Connection();
$this->DebugMemUsage('Got error'.$this->error);
返回数组(false,$this->错误);
}
$this->DebugMemUsage('Mail accepted');
/**
*我们走了这么远,这意味着我们没有遇到任何错误。
*清除以前的错误代码和变量,因为它们不再相关
*使用当前流程迭代。
*/
$this->Error='';
$this->ErrorCode=false;
$this->errorcodesmtprecensed=false;
$this->_smtp_email_count++;
返回数组(真、假);
}

最后,“bug”出现在另一个功能中,即密件抄送功能;在工作过程中的每次调用中,都不是清除以前的密件抄送副本,而是将它们相加,直到它们达到极限。

也许我们可以有一些代码,也许是一个发送循环?我要回答这个问题……等等,你的问题与应用程序结构有关,而不是任何东西。检测你的脚本是否“崩溃”在完成并再次启动之前,它看起来比每次运行时发送更少副本更复杂。脚本不会崩溃,它只是可以在有密件抄送时和发送1000封电子邮件后与stmp协商