Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sendmails works, but opens 43 file handles per email -> problem

Status
Not open for further replies.

ZX81Fan

Programmer
Dec 16, 2010
1
DE
I'm using Sendmail 8.13.8 on a CentOS 5.5 vServer (Virtuozzo).

I'm using a loop in PHP to send a lot of HTML-mails via sendmail. Each mail is a mail with individual statistics for our users, so its not mass mailing, bcc is not an option.

It all works fine, but when I take a closer look there is a problem heading our way with a high number of mails:

For each mail sendmail opens up 43 files. Sometimes these open files get closed again very fast, sometimes not.

Here is an example using the PHP-script below, it sends 20 mails in a loop:


[root]# php test-mail.php
START: number of open files: 2113
END: number of open files: 2973


This is the worst case. The number of open files (lsof | wc -l) used to send the 20 mails is 860 => 43 open files per mail.

Sometimes the files are closed very fast, so I get results like this, too:


[root]# php test-mail.php
START: number of open files: 2113
END: number of open files: 2242


This shows 129 (3 * 43) open files, so the open files for 17 send mails are already closed, for 3 mails the 129 files are still open.

In the worst case and with lots of mails our server crashes, the numfile limit of 8192 in user_beancounters is reached (our ISP won't give us more than 8192).

Sendmail DeliveryMode is background.

Could it be that sendmail tries to send lots ob mails asyncronously and uses 43 open files for each? I'm only depending on sendmail to deliver the mails, normaly I wouldn't dare to touch the sendmail config (like 'if you don't know what you're doing, don't!').

Any ideas?

BTW: It is not a problem of PHP. I verified this by sending mails via SMTP localhost to sendmail (opened 43 files per mail) and sending mails via SMTP to an ISP-relay (did not open any files per mail).

Thank you very much for reading this,
best,
Andreas


This is the code for test-mail.php:

Code:
<?php
$output = shell_exec('lsof | wc -l');
echo "START: number of open files: $output";

// HTML message
$msg = '<html><head><title>Test mail</title></head><body><p>Mailbody</p></body></html>';

// Set 'Content-type'-header
$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

for($i=0; $i<20; $i++) {
	// send mail, this opens up 43 files for each
	mail('you@yourdomain.com', 'Testmail '.$i, $msg, $header, '-f [email]bounce@yourdomain.com[/email]');
}

$output = shell_exec('lsof | wc -l');
echo "END: number of open files: $output";
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top