I'm writing a php program to extract emails from a microsoft exchange
server and write them to files on my linux box. I'm having a problem
which looks like a memory leak in imap_body(). But I find it hard to
believe that nobody has noticed it before, so I am probably doing
something wrong.
If I watch the program using top, the SIZE and RSS rapidly increase
until the program hits the size limit. I can workaround the problem by
moving the calls to imap_open() and imap_close() inside the loop. The
imap close frees the memory that imap_body allocated, but it's very
slow and inefficient to do it that way.
If I comment out the call to imap_body() then the memory usage does not
increase, so it's definitely that line causing the problem.
I am currently using php as supplied with Fedora1. I will upgrade to a
newer version
and see if that helps.
Here's the code, expert advice please...
#!/usr/bin/php
<?php
{
$folder="{mailserver.domain.com:143}INBOX";
$mailbox="DOMAIN\\user\\user";
$authpass="password";
$mbox = imap_open($folder,$mailbox,$authpass,OP_READONLY);
if (!$mbox)
{
print "imap_open() failed.\n";
exit(1);
}
$message_count=imap_num_msg($mbox);
for ($i=1;$i<=$message_count;$i++)
{
$body = imap_body($mbox,$i,FT_PEEK);
$outfile=fopen($i.".mime","w");
if (!$outfile)
{
print "fopen() failed,\n";
exit(2);
}
fwrite($outfile,$body);
fclose($outfile);
}
imap_close($mbox);
}
?> 2 3172 ph********@vicorp.com wrote: If I comment out the call to imap_body() then the memory usage does not increase, so it's definitely that line causing the problem.
You are storing the output of imap_body() into a variable, which may be the
cause of your problem (with large emails).
$body = imap_body($mbox,$i,FT_PEEK); $outfile=fopen($i.".mime","w"); if (!$outfile) { print "fopen() failed,\n"; exit(2); } fwrite($outfile,$body); fclose($outfile);
Try to do it like this:
if (!$outfile = @fopen($i.".mime","w")) {
print "fopen() failed,\n";
exit(2);
}
fwrite($outfile, imap_body($mbox, $i, FT_PEEK));
fclose($outfile);
JW
Hi JW,
Thanks for the suggestions. I've followed you advice, but the problem
remains. The memory usage increases with every call to imap_body(). I
guess is really is a problem with PHP rather than with my code.
I've now upgraded PHP to 4.3.8-1.1, which is the latest rpms released
by RedHat for Fedora 1. The only option I can think of is to download
and compile the very latest version, but I'm not hopefull because I
don't see anything in the changelog relating to this problem.
Thanks again.
Phil. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joachim Smit |
last post by:
Is it possible to extract the email-body from a IMAP-mail-file ?
The function 'imap_body()' expects that I'm connected to an IMAP-server, but
I'm not. I just have the file.
So I'm looking for...
|
by: Dafella |
last post by:
The following is code from Xeoport.
It is suppose to access my pop3 account and load email into Mysql
database.
It's not inserting and there is no log or anything to tell me why.
Here is the...
|
by: mattoneill |
last post by:
Im having problems getting the MIMEDecode PEAR function working, not
sure how it expects the messages to be parsed to it, cause currently
this is not working:
@...
|
by: elyob |
last post by:
Hi, I'm looking to setup an email system that will log into a catchall
account, read to addresses and forward them to a different email address
stored in a MySQL table. I may also allow the users...
|
by: s_boucher |
last post by:
Hi,
I'm trying to fetch the body of a specific usenet message using the
imap_body function with the FT_UID option (The msg_number is a UID).
My understanding is that the UID is the string that...
|
by: chris_fieldhouse |
last post by:
Hi,
I have a script for processing emails,
The script finds email sent to a particular alias, grabs the body text
of the email and stores it into a database.
Problem is that certain character...
|
by: [ Nicola ] |
last post by:
Using imap i must zap through emails in my email address, then saving
part of the message (the main body that is).
Question is, how am i supposed to read only the message's content,
ignoring all...
|
by: bill |
last post by:
Turning on error_reporting(E_ALL); was quite an eye opener as to
how much "fixing" PHP will do for the sloppy coder.
I fixed all of the errors except:
Notice: Undefined property: parts in...
|
by: shmick30 |
last post by:
Hi There,
I am looping through and reading the body contents of a mail box with
over 200 emails in it. The script is running very slow and timing out
after 180 seconds, only getting through...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |