note 95012 added to function.imap-headerinfo
| From: | jahservant13atgmaildotcom at osu1 dot php dot net | Date: | Tue, 08 Dec 2009 23:56:48 +0000 |
| Subject: | note 95012 added to function.imap-headerinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163723@lists.php.net to get a copy of this message | ||
I'm not entirely sure why this is, but if you loop through all of the messages in a mailbox,
calling imap_header() each time, you can significantly increase performance by calling
imap_headers() first.
Compare this:
<?php
$imap = imap_open("{my.server.com:143}INBOX", "user", "pass");
$n_msgs = imap_num_msg($imap);
$s = microtime(true);
for ($i=0; $i<$n_msgs; $i++) {
$header = imap_header($imap, $i);
}
$e = microtime(true);
echo ($e - $s);
imap_close($imap);
?>
With this:
<?php
$imap = imap_open("{my.server.com:143}INBOX", "user", "pass");
$n_msgs = imap_num_msg($imap);
/****** adding this line: ******/
imap_headers($imap)
/***************************/
$s = microtime(true);
for ($i=0; $i<$n_msgs; $i++) {
$header = imap_header($imap, $i);
}
$e = microtime(true);
echo ($e - $s);
imap_close($imap);
?>
The performance difference, as I have tested on several boxes, connecting to several different
servers, is that the second code snippet ALWAYS takes 1/2 the time, if not less.
Perhaps it is because imap_headers() retrieves all of the messages on one connection, whereas
imap_header() has to make a new fetch request for each message?? I'm not sure WHY it is faster
if imap_headers() is called first, but I do know that it is, so I thought I'd pass on the
knowledge. If anyone knows why this is, please let me know....
----
Server IP: 69.147.83.197
Probable Submitter: 216.85.118.110
----
Manual Page -- http://www.php.net/manual/en/function.imap-headerinfo.php
Edit -- https://master.php.net/note/edit/95012
Del: integrated -- https://master.php.net/note/delete/95012/integrated
Del: useless -- https://master.php.net/note/delete/95012/useless
Del: bad code -- https://master.php.net/note/delete/95012/bad+code
Del: spam -- https://master.php.net/note/delete/95012/spam
Del: non-english -- https://master.php.net/note/delete/95012/non-english
Del: in docs -- https://master.php.net/note/delete/95012/in+docs
Del: other reasons-- https://master.php.net/note/delete/95012
Reject -- https://master.php.net/note/reject/95012
Search -- https://master.php.net/manage/user-notes.php