php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Slow message loading

Open skurrilewelt opened this issue 2 years ago • 5 comments

Hi,

some folks reported slow message fetching and all tickets are closed but there is no solution mentioned. I tried both v4 and v5. The bottle neck is looping through paginated messages and takes 8 to 10 sec for 20 messages. Maybe I'm doing wrong but in my code everything is similar more or less to the example code. Even if I leave everything out in the foreach loop there is no improvement.

Maybe someone has any clue?

skurrilewelt avatar May 11 '23 05:05 skurrilewelt

Hi,

some folks reported slow message fetching and all tickets are closed but there is no solution mentioned. I tried both v4 and v5. The bottle neck is looping through paginated messages and takes 8 to 10 sec for 20 messages. Maybe I'm doing wrong but in my code everything is similar more or less to the example code. Even if I leave everything out in the foreach loop there is no improvement.

Maybe someone has any clue?

The only way I know is to put the PHP code, in the same hosting you aim. 4 seconds took, now ~ 300ms. (If it is Gmail/Hotmail, perhaps forwarding an email of your domain and there to use this project)

firecrauter avatar Feb 04 '24 18:02 firecrauter

I made some tests with another imap library which depends on build-in php imap methods and builds some classes upon them. The test setup uses both the simplest example code given by the contributors. Connecting to the same account and same mailbox, fetching 62 Messages, most of them with one or more attachments, looping through messages and display subject and number of attachments. Results:

PHP7.4.23 Webklex 4.1.2 => 29 sec, DDeboer => 0.7 sec PHP8.1.6 Webklex 5.3 => 91 sec, DDeboer =>0.7 sec

I repeated this tests several times with no significant differences in result.

So it seems that there is no performance enhancement in version 5.

Maybe someone can explain this or has any idea how to improve webklex' performance because this lib is really awesome in al other aspects.

skurrilewelt avatar Feb 21 '24 07:02 skurrilewelt

Would you happen to have any updates? i guess the problem is this line while (($next_char = fread($this->stream, 1)) !== false && !in_array($next_char, ["","\n"])) { it loops for 20,000 times calling fread not sure if this is correct! which lib do you use now?

I made some tests with another imap library which depends on build-in php imap methods and builds some classes upon them. The test setup uses both the simplest example code given by the contributors. Connecting to the same account and same mailbox, fetching 62 Messages, most of them with one or more attachments, looping through messages and display subject and number of attachments. Results:

PHP7.4.23 Webklex 4.1.2 => 29 sec, DDeboer => 0.7 sec PHP8.1.6 Webklex 5.3 => 91 sec, DDeboer =>0.7 sec

I repeated this tests several times with no significant differences in result.

So it seems that there is no performance enhancement in version 5.

Maybe someone can explain this or has any idea how to improve webklex' performance because this lib is really awesome in al other aspects.

osamasc avatar Jun 06 '24 19:06 osamasc