3

BACKGROUND: I just migrated my project to a different server (a shared DigitalOcean one, the cheapest offer) with CentOS, and noticed that PHP's imap functions take way more on the new server, than on the old one(like 10x more).

The old server is a dedicated server, and a mail server is also hosted on the old server, the one which I am trying to perform imap actions on.

IMPORTANT: I don't think that this slow down has anything to do with not trying to connect from the same physical server to the mail server anymore, because of the severe increase of the time it requires to run any imap function throughout my project, but anyone can prove me wrong, because I don't know anything about networking unfortunatly:(

I've made some simple script runtime test on both servers, by creating two php files, and testing the execution time of both, one using only php's imap functions (imap_open), and another one, where I am using PEAR Net_IMAP package. Here are the two scripts:

SCRIPT 1:

$start=microtime(true);
$temp=$start;
$mbox = imap_open ("{mymailserver:143/novalidate-cert}INBOX", "email@address.com", "password");
telltime($start, "Connect and Login", $temp);
$mbox = imap_reopen ($mbox,"{mymailserver:143/novalidate-cert}INBOX.Sent");
telltime($start, "Changefolder", $temp);
telltime($start, "End script");

SCRIPT 2:

require_once 'Net/IMAP.php'; 
$imapServer = new Net_IMAP('mymailserver', 143);
telltime($start, "Connect", $temp);
$loggedIn = $imapServer->login('email@address.com' , 'password'); 
telltime($start, "Login", $temp);
$imapServer->selectMailbox("INBOX.Sent");
telltime($start, "Change folder", $temp);
telltime($start, "End script");

I've ran these scripts the following way, with the following results:

SCRIPT 1 AS IS - old server

Connect and Login: 0.124350070953
Changefolder: 0.00585293769836
Whole time: 0.130313158035

SCRIPT 1 AS IS - new server

Connect and Login: 0.63277888298035
Changefolder: 0.15838479995728
Whole time: 0.79174709320068

SCRIPT 1 /novalidate-cert changed to /notls - old server

Connect and Login: 0.112071990967
Changefolder: 0.00407910346985
Whole time: 0.116246938705

SCRIPT 1 /novalidate-cert changed to /notls - new server

Connect and Login: 0.50686407089233
Changefolder: 0.17428183555603
Whole time: 0.68127012252808

SCRIPT 2 AS IS - new server

Connect: 0.42295503616333
Login: 0.4013729095459
Change folder: 0.057337045669556
End script: 0.88185501098633

The project also has a console based debugging system, from which I've managed to gather the following information:
- an average search to the mailbox takes around 0.01-0.02 seconds on the old server, while on the new server, the same search takes around 7-8x times more
- the fetching of a single e-mail from the mail server on the old server takes between 0.05s-0.1s while on the new server, there are e-mails(mainly those which have Text/HTML with attached image files) which take 4 seconds to fetch

Based on these results, I am presuming that I am facing a networking problem, but it is just a wild assumption, as till now I've never debugged networking errors, but I already took apart my php scripts, and I can't find any error in them.

I tried traceroute-ing and ping-ing the mail server from the new project environment, and I've got the following results:

traceroute to mymailserver (xxx.xxx.xxx.xx), 30 hops max, 60 byte packets
1  xxx.xxx.x.xxx 0.658 ms xxx.xxx.x.xxx 0.510 ms xxx.xxx.x.xxx 0.471 ms
2  xxx.xxx.xxx.xxx  0.434 ms xxx.xxx.xxx.xxx 0.333 ms xxx.xxx.xxx.xxx 0.247 ms
3  xxx.xxx.xxx.xx 0.984 ms  0.986 ms xxx.xxx.xxx.xxx 0.270 ms
4  xxx.xxx.xxx.xx 0.964 ms xxx.xxx.xx.xxx 1.414 ms  1.449 ms
5  xxx.xxx.xx.xxx 1.253 ms  1.211 ms xxx.xxx.xx.xxx 22.078 ms
6  xxx.xxx.xx.xxx 43.920 ms  41.971 ms  44.860 ms
7  xx.xx.xx.xxx 45.835 ms xxx.xxx.xx.xxx 42.055 ms  41.254 ms
8  * xxx.xxx.xxx.xxx 42.999 ms *
9  xxx.xxx.xxx.xx 41.989 ms  42.235 ms  44.925 ms

Yes, sometimes traceroute reports about lost packages, but not always, but the rest of this information unfortunatly is only giberish to me, cause I don't understand for what I have to look for, and I didn't find any usable tutorial for traceroute on the internet.

** OTHER INFORMATION BASED ON THE HELP FROM OTHER STACKOVERFLOW USERS: **
I've also downloaded xDebug, and tried function tracing the two above mentioned scripts. While I didn't get any usefull information by function tracing imap_open function, I've noticed that when I function trace the PEAR package, the fgets() that are performed somewhere in the class, take considerably more time, than any other function that is being run(around 0.05 seconds)

My question(s):
- Am I right in assuming from these information that this has to be a networking problem?
- If yes, how could I solve it, or what are the giveaways that this is indeed a networking problem?
- If no, how could I isolate the problem better, and obtain a solution to it?

I am offering a:
- a thank you, to someone who helps me isolate if this is a networking problem, or something else
- a bounty, if someone manages to help me solve this issue, and speed up the processing of imap functions

Adam Baranyai
  • 3,635
  • 3
  • 29
  • 68
  • Did you tried anything? XDebug, maybe? – al'ein Sep 17 '15 at 16:02
  • I don't know what XDebug is:| – Adam Baranyai Sep 17 '15 at 16:03
  • did you notice that everything else is slower too – Drew Sep 17 '15 at 16:07
  • Only a tiny bit. The new server is a virtual server, so it is slower than the older one, but the rest of my scripts are only slower by miliseconds – Adam Baranyai Sep 17 '15 at 16:10
  • IMAP is header-reading protocol, so it can be related to connection issues. I strongly suggest that you read, learn and try to use xDebug, it can give you more info on the matter. The way you put the question is very unclear since we don't know your full code, both of your server's architectures and related installed softwares – al'ein Sep 17 '15 at 16:13
  • Okay, I've installed xDebug but I am at a loss in what to do right now:| I am reading the documentation for now, but a heads-up quick start would be really usefull:) – Adam Baranyai Sep 17 '15 at 16:21
  • http://xdebug.org/docs/all if you have already installed xDebug and configured it, go all the way down to Function Traces, that's what you'll want. Use the methods as described on the function you call to use IMAP on your script runtime test. – al'ein Sep 17 '15 at 16:50
  • 1
    Okay, tried tracing imap_open function, but nothing new arise, in the trace file, it only stated the name of that function, and the time it run. But, I've tried switching to Net_IMAP Pear package, and also traced that. The script runs in almost the same ammount of time with this PEAR package on the new server(0.6-0.7s), but I've gained some more information this time from the XDebug traces. As it seems from the trace file, running fgets() function takes a bit more time, than any other function which the package runs. – Adam Baranyai Sep 17 '15 at 17:07
  • 1
    You've said you're in a virtual environment, meaning the network device isn't physical, but emulated and shared. You can be facing resource concurrency within an specific function at runtime, something you didn't face when you were "talking" directly to the interface. I'm sorry I can't help you out anymore than this, I can't simulate your problem here, but I hope you find what it is that's hanging you. – al'ein Sep 17 '15 at 17:16

0 Answers0