From 09e765ba1331dd514b3df08ae7efba1709514e11 Mon Sep 17 00:00:00 2001 From: felixww Date: Wed, 27 Feb 2013 12:56:45 +0100 Subject: [PATCH] Update scripts/jobs/cron_autoresponder.php Emails used to be read for parsing, using PHP's file() command. I changed it to read the file line by line, so the script doesn't run into the PHP memory limit. Note that this has been a severe bug, since it used to make PHP abort script execution, thus possibly losing many emails for many users (i.e, on a multi domain setup with many autoresponders running). --- scripts/jobs/cron_autoresponder.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/jobs/cron_autoresponder.php b/scripts/jobs/cron_autoresponder.php index c826c3d3..00861e1e 100644 --- a/scripts/jobs/cron_autoresponder.php +++ b/scripts/jobs/cron_autoresponder.php @@ -97,8 +97,19 @@ if($db->num_rows($result) > 0) $filemtime = $it->getMTime(); if(time() - $filemtime <= $cycle) { - $content = file($fullFilename); - + // why not read up to k lines? + // I've been patching this forever, to avoid FATAL ERROR / memory exhausted + // (fgets() is now binary safe, too) + // $content = file($fullFilename); + $lcount = 0; $content = array(); $handle = @fopen($fullFilename, "r"); + if ($handle) { + // 1023 lines of an email should be enough to analyze it + while (($count++<1023) && (($buffer = fgets($handle)) !== false)) { + $content[]=$buffer; + } + fclose($handle); + } + // error reading mail contents or just empty if(count($content) == 0) {