473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

imap_body()


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);
}
?>

Jul 17 '05 #1
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

Jul 17 '05 #2
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.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
0
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...
1
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: @...
4
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...
0
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...
6
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...
1
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...
8
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.