restrive Posted August 24, 2008 Share Posted August 24, 2008 I have a website that was previously hosted on a standard Apache/PHP Debian server. The website was recently moved over to our new CPanel server. Everything works fine except when we do a mailshot we send out about 6000 email rapidly using a PHP script, the page that loads times out and the process crashes. It used to wait until the mails were all sent out, but now the pages "crashes" without any set reason. It about every 100th email but that and the time is different every time. The maximum each domain can send out per hour is set to 0 (unlimited) From the logs we have found this: [error] PHP Fatal error: Out of memory (allocated 1572864) (tried to allocate 532481 bytes) The server however has more than enough available RAM Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/ Share on other sites More sharing options...
DarkWater Posted August 24, 2008 Share Posted August 24, 2008 Can we see the script? Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624327 Share on other sites More sharing options...
restrive Posted August 24, 2008 Author Share Posted August 24, 2008 I have extracted the faulty section (thanks in advance): if ($submit == "Send") { if ($step998 == "errorsOnly") { $edition=$_POST['edition']; $editorial=$_POST['editorial']; } else { if ($step1001 == "errorsOnly") { $edition=$_POST['edition']; $editorial=$_POST['editorial']; } else { $editorial=$step3; $sql_edition = "SELECT edition FROM articles ORDER BY edition"; $result_edition = mysql_query($sql_edition) or die("invalid query: " . mysql_error()); while ($row = mysql_fetch_array($result_edition)) { extract($row); } $edition++; $sqlIns = "INSERT INTO editions (edition, date, editorial) VALUES ('" . $edition . "', '" . date(Ymd) . "', '" . $step3 . "')"; $resultIns = mysql_query($sqlIns) or die("invalid query: " . mysql_error()); for ($i=1; $i<=$_POST['count']; $i++) { if ($_POST['art' . $i] == "on") { $sql = "UPDATE articles SET edition='" . $edition . "' WHERE id='" . $_POST['artID' . $i] . "'"; $result = mysql_query($sql) or die("invalid query: " . mysql_error()); } } } } include('create_email.php'); foreach(file("newsletter/email.html") as $line) { $mailBody .= $line; } //$headers = "FROM: [email protected]\n"; $headers = "FROM: World Outdoor News <[email protected]>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type:text/html;charset=utf-8\n"; step6(); if ($step998 == "errorsOnly" || $step1001 == "errorsOnly") { $sql = "SELECT email FROM subscribers WHERE send='yes' && edition<>'" . $edition ."'"; } else { $sql = "SELECT email FROM subscribers WHERE send='yes'"; } $result = mysql_query($sql) or die("invalid query: " . mysql_error()); $successLog = fopen("newsletter/log/success.txt","w+"); $failedLog = fopen("newsletter/log/failed.txt","w+"); $summaryLog = fopen("newsletter/log/summary.txt","w+"); $successCount = 0; $failedCount = 0; //Create the log html email... $emailHTML = fopen("newsletter/log/report.html","w+"); fwrite($emailHTML, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'); fwrite($emailHTML, "\n\n<html>\n"); fwrite($emailHTML, "\n<head>\n"); fwrite($emailHTML, "\n" . '<link rel="stylesheet" type="text/css" href="' . $siteUrl . '/won.css" />' . "\n"); fwrite($emailHTML, "\n<style>\nbody\n{\nbackground-color: #EAEAEA;\n"); fwrite($emailHTML, " margin: 0px;\n margin-left: 0px;\n margin-bottom: 54px;\n}\n"); fwrite($emailHTML, "</style>\n\n<title>company - mail shot report</title>\n\n"); fwrite($emailHTML, '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'); fwrite($emailHTML, "\n\n</head>\n\n<body>\n\n"); fwrite($emailHTML, '<table border="1" width="400" bgcolor="#EAEAEA" cellpadding="0" cellspacing="0">'); fwrite($emailHTML, "\n <tr>\n <td valign=\"top\" bgcolor=\"#353535\">\n"); fwrite($emailHTML, "\n <h1>Mail Shot Report - " . $todayDate . " - Summary</h1>\n"); fwrite($emailHTML, " </td>\n </tr>\n"); fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); while ($row = mysql_fetch_array($result)) { extract($row); dispSend('Sending mail to...'); $mailStatus=mail($email,"company",$mailBody,$headers); //$mailStatus=1; if ($mailStatus == 1) { fwrite($successLog, "Successfully sent mail to " . $email . "\n"); $successCount++; $sqlDate = "UPDATE subscribers SET edition='" . $edition . "' WHERE email='" . $email . "'"; $resultDate = mysql_query($sqlDate); } else { fwrite($failedLog, "Failed to send mail to " . $email . "\n"); $failedCount++; } } fwrite($summaryLog, "Successfully sent " . $successCount . "mails\n"); fwrite($summaryLog, "Failed to send " . $failedCount . "mails\n"); fclose($failedLog); fclose($successLog); fclose($summaryLog); fwrite($emailHTML, " <strong>Successfully sent " . $successCount . " mails</strong>\n"); fwrite($emailHTML, " </td>\n </tr>\n"); fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); fwrite($emailHTML, " <strong>Failed to send " . $failedCount . " mails</strong>\n"); fwrite($emailHTML, " </td>\n </tr>\n"); fwrite($emailHTML, "</table>\n<br/>\n"); fwrite($emailHTML, '<table border="1" width="400" bgcolor="#EAEAEA" cellpadding="0" cellspacing="0">'); fwrite($emailHTML, "\n <tr>\n <td valign=\"top\" bgcolor=\"#353535\" align=\"center\">\n"); fwrite($emailHTML, "\n <h1>Failed Email Addresses</h1>\n"); fwrite($emailHTML, " </td>\n </tr>\n"); if ($failedCount == 0) { fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); fwrite($emailHTML, " <strong>Their were no failed emails.</strong>"); fwrite($emailHTML, " </td>\n </tr>\n"); } else { foreach(file("newsletter/log/failed.txt") as $line) { fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); fwrite($emailHTML, " <strong>" . $line . "</strong>"); fwrite($emailHTML, " </td>\n </tr>\n"); } } fwrite($emailHTML, "</table>\n<br/>\n"); fwrite($emailHTML, '<table border="1" width="400" bgcolor="#EAEAEA" cellpadding="0" cellspacing="0">'); fwrite($emailHTML, "\n <tr>\n <td valign=\"top\" bgcolor=\"#353535\" align=\"center\">\n"); fwrite($emailHTML, "\n <h1>Successfull Email Addresses</h1>\n"); fwrite($emailHTML, " </td>\n </tr>\n"); if ($successCount == 0) { fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); fwrite($emailHTML, " <strong>Their were no successfull emails.</strong>"); fwrite($emailHTML, " </td>\n </tr>\n"); } else { foreach(file("newsletter/log/success.txt") as $line) { fwrite($emailHTML, " <tr>\n <td valign=\"top\" align=\"center\" bgcolor=\"#FFFFFF\">\n"); fwrite($emailHTML, " <strong>" . $line . "</strong>"); fwrite($emailHTML, " </td>\n </tr>\n"); } } fwrite($emailHTML, "</table>\n<br/>\n"); fwrite($emailHTML, "</body>\n</html>"); fclose($emailHTML); foreach(file("newsletter/log/report.html") as $line) { $mailBodyAdm .= $line; } $emailArray=explode("|",$admEmail); foreach ($emailArray as $emailAdm) { $mailStatusAdmin=mail($emailAdm,"Mail Shot Report",$mailBodyAdm,$headers); } $dispString="Successfully sent " . $successCount . " mails.<br/>"; $dispString.="Failed to send " . $failedCount . " mails.<br/>"; if ($mailStatusAdmin == 1) { $dispString.="Successfully sent mail shot report to: " . $admEmail; ?> <input type="hidden" id="str2" value="<?php echo $dispString; ?>"> <script> var str2 = document.getElementById("str2").value document.getElementById("sendingEmail").innerHTML=str2 </script> <?php } else { $dispString.="Failed to send mail shot report to: " . $admEmail; ?> <input type="hidden" id="str2" value="<?php echo $dispString; ?>"> <script> var str2 = document.getElementById("str2").value document.getElementById("sendingEmail").innerHTML=str2 </script> <?php } } Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624340 Share on other sites More sharing options...
DarkWater Posted August 24, 2008 Share Posted August 24, 2008 I'm thinking that all those fwrite() calls are eating away at your memory. Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624343 Share on other sites More sharing options...
restrive Posted August 24, 2008 Author Share Posted August 24, 2008 The strange thing is that on the previous server (which had less memory) it worked 100%. Do you think it could help to put in some kind of pause? Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624345 Share on other sites More sharing options...
DarkWater Posted August 24, 2008 Share Posted August 24, 2008 No, I think you should just condense it all to one file_put_contents(). Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624347 Share on other sites More sharing options...
restrive Posted August 24, 2008 Author Share Posted August 24, 2008 The failure occurs in this loop below, do you mean that I shouldn't change the fwrite's in here into a array and then put them into the file after the loop: while ($row = mysql_fetch_array($result)) { extract($row); dispSend('Sending mail to...'); $mailStatus=mail($email,"Wonsa",$mailBody,$headers); //$mailStatus=1; if ($mailStatus == 1) { fwrite($successLog, "Successfully sent mail to " . $email . "\n"); $successCount++; $sqlDate = "UPDATE subscribers SET edition='" . $edition . "' WHERE email='" . $email . "'"; $resultDate = mysql_query($sqlDate); } else { fwrite($failedLog, "Failed to send mail to " . $email . "\n"); $failedCount++; } } Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624352 Share on other sites More sharing options...
restrive Posted August 24, 2008 Author Share Posted August 24, 2008 Thanks DarkWater!! :) :) It was the fwrite() Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624423 Share on other sites More sharing options...
DarkWater Posted August 24, 2008 Share Posted August 24, 2008 Lol, I thought so. Sorry for not responding though, I went to play Mario Kart. Link to comment https://forums.phpfreaks.com/topic/121105-php-mail-support/#findComment-624424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.