Reputation: 2736
I have a web app which generates hundreds of emails per day and one of the most common support requests is why has my email not arrived - in most cases, the mail has been sent by us but has gotten delayed or rejected by the receiver
The only way we can tell is to SSH into the server, open exim log file and search for the email address which is time consuming and also potentially "dangerous" as we don't want support staff logging in via SSH in case they do something dumb.
We want to have a simple way of displaying the contents of /var/log/exim/main.log via https in our support portal. The file is just under 1MB in size at the moment.
At this stage we have used:
$file = file('/var/log/exim/main.log');
foreach ($file as $row) {
print $row."<br>";
}
We have done it this way as it shows each line in its own line and makes it more readable - it works fine for the around the first 1000 lines/rows and then the pagination "breaks".
If we print the array using
print_r($file);
it shows fine but as soon as we loop through it stops working at entry 1054 in the array.
For example, we get:
2014-03-24 01:06:45 cwd=/home/domain/public_html 3 args: /usr/sbin/sendmail -t -i
2014-03-24 01:06:45 1WRtLh-0001ke-5K <= [email protected] U=apache P=local S=810 T="Message" from for [email protected]
2014-03-24 01:06:45 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1WRtLh-0001ke-5K
2014-03-24 01:06:48 1WRtLh-0001ke-5K => [email protected] F= R=dnslookup T=remote_smtp S=827 H=mx1.mx [1.1.1.1] C="250 2.0.0 Ok: queued as C7E5F301206" 2014-03-24 01:06:48 1WRtLh-0001ke-5K Completed 2014-03-24 01:10:26 cwd=/home/domain/public_html/send 3 args: /usr/sbin/sendmail -t -i 2014-03-24 01:10:26 1WRtPG-0001lw-7y <= [email protected] U=apache P=local S=825 T="Message 2" from
for [email protected] 2014-03-24 01:10:26 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1WRtPG-0001lw-7y 2014-03-24 01:10:29 1WRtPG-0001lw-7y => [email protected] F=
and from then on the pagination is broken.
Is there a limit to the size of a file or number of items in an array read in this way? If not, any idea why this is happening?
Upvotes: 0
Views: 239
Reputation: 897
The code looks OK and should work. I guess there is some problem with the memory allocation. The following link could be of some help.
Where to edit for increase in memory in PHP ini file?
Upvotes: 1
Reputation: 7569
If it's just an email address you're searching for, why not just have a form where they can submit the email address they're searching for, and have your php script read through the file searching for that address? There's no reason to manually do the search that way, unless i'm misunderstanding the question?
Upvotes: 0