Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvement, my solution #154

Closed
j4r3kb opened this issue Jun 27, 2016 · 1 comment
Closed

Performance improvement, my solution #154

j4r3kb opened this issue Jun 27, 2016 · 1 comment
Labels
question This issue is about one or more questions regarding this library.

Comments

@j4r3kb
Copy link

j4r3kb commented Jun 27, 2016

Hello,
I'm using this bundle in company project. When I connected mailbox with 18000+ mails in INBOX folder and tried to load them all (don't ask why ;)) it took forever. After some research I learned that mails can be fetched by sequence number or UID. So I extended your Mailbox Class and done the following:

public function searchMailbox($criteria = 'ALL') {
    $mailsIds = imap_search($this->getImapStream(), $criteria, SE_FREE, $this->serverEncoding);
    return $mailsIds ? $mailsIds : array();
}

SE_FREE instead of SE_UID

and:

public function getMailsInfo(array $mailsIds) {
    $mails = imap_fetch_overview($this->getImapStream(), implode(',', $mailsIds), 0);
...

0 instead of FT_UID.

Those two changes made execution of imap_fetch_overview ~15 times faster. For example fetching 8000 mails took 90.4 seconds on stock and 5.6 seconds with above changes. I compared the search results (to check if some emails where missed) with both methods and they were same.
However, if given range of emails is fetched for the first time it takes equal time in both cases. Only following fetches are faster with my method.
Could you explain this case for me?

@barbushin barbushin added the question This issue is about one or more questions regarding this library. label Oct 6, 2017
Sebbo94BY pushed a commit that referenced this issue May 1, 2019
@Sebbo94BY
Copy link
Collaborator

SE_FREE is usually faster, because it's just an incremental ID starting at 1 while SE_UID is the unique ID for each email, which needs to be retrieved somewhere first. Retrieving the UID takes usually some time and depending on the server, it's sometimes faster or slower.

I've committed a change, which allows user of this library to change this option:

$mailbox->getImapSearchOption(); // Default is SE_UID
$mailbox->setImapSearchOption(SE_FREE); // Note: Parameter must be a constant!
$mailbox->getImapSearchOption(); // We changed it, so it will return SE_FREE

The new functions will be included in the next release.

Sebbo94BY added a commit that referenced this issue May 5, 2019
- Updated README
- Move phpunit to require-dev
- Add note about installing dev dependencies in README
- Replaced spaces with tabs
- Added PHPUnit tests for MIME decoding
- Updated formatting of PHPUnit function testParsedDateTimeWithEmptyHeaderDate()
- Issue #209: Function to parse datetime correctly RFC2822
- Issue #280: Added 'Sender' to headers and added additional if-conditions 
- Issue #115: getMail() method returns an object even for nonexistent mail ID
- Issue #273: Added connection check to example
- Issue #227: Added Failed-Recipients to IncomingMailHeader
- Issue #140, #246: Improved exception handling and added PHPUnit test
- Issue #140: Added PHPUnit test for testing ConnectionException
- Issue #140: Improved exception / error handling and improved / added PHPUnit tests
- Issue #154: Added ability to change the imap_search option from SE_UID to SE_FREE and added PHPUnit tests
- Issue #306: Added support for US-ASCII and added ability to disable serverEncoding for searchMailbox()
- Imported missing namespaces to avoid 'unknown class' error messages
- Issue #86: Simplified and improved one replace regex for attachment file names
- Issue #247: Improved grabbing of fromName, fromHost, senderName and senderHost
- Issue #39, #71, #229: Fixed body content gets incorrectly processed as attachments
- Issue #122, #150, #167: Added ability to skip processing of attachments to increase performance, when attachments are not required
- PR #284: Added missing PHPUnit tests
- Issue #122, #150, #167: Lazy load message text and attachments data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is about one or more questions regarding this library.
Projects
None yet
Development

No branches or pull requests

3 participants