13

Ive just started to encounter a problem with MAMP PHP running extremely slowly. Ive reinstalled MAMP and still having issues.

As a comparison (I thought maybe my local development OS X machine may have been having issues) i tried the following in terminal, and disabled php.ini with -n

/usr/bin/php --version -n

This returns with an output immediately.

/Applications/MAMP/bin/php/php5.5.14/bin/php --version -n 

This returns an output approx 3-5 seconds later.

I have tried running numerous other commands and scripts. All seem to have a delay of 3-5 seconds with MAMP PHP.

I have tried other MAMP PHP versions, and they still have the same issues.

I can't think of anything that has changed recently on my machine to cause this slow down (e..g no php.ini changes, no OS X updates)

I really have no idea whats causing this problem, or even how to investigate things further. Help greatly appreciated.

UPDATE

Strangely, the problem only seems to be when running MAMP PHP in command line. When loading a website using MAMP, there is no slow down. Even more confusing...

GWed
  • 15,167
  • 5
  • 62
  • 99
  • Wrong place to ask this question. Have a try over at the ServerFault sister page. – arkascha Mar 20 '15 at 11:44
  • 1
    I disagree - "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." - this is about my development environment, so surely belongs here? – GWed Mar 20 '15 at 11:49
  • Ah, sorry, usually a LAMP stack (or similar) is used to create business related solutions. Keep in mind that business does not mean commercial. It certainly is your decision. I just thought you will get faster and better replies over there. – arkascha Mar 20 '15 at 11:52
  • Ok thanks. I'll keep it here as Server Fault relates more to production servers. Im talking about my development laptop running MAMP. The slow down is driving me nuts! – GWed Mar 20 '15 at 11:54
  • @arkascha: Products namend MAMP/XAMPP etc. are dev tools, as opposed to the standard LAMP stack, and they are actually off-topic on SF. – Sven Mar 20 '15 at 11:57
  • @arkascha MAMP is a "tool primarily used for programming" and as such questions about it really don't belong on [sf]. – Michael Hampton Mar 20 '15 at 13:57

2 Answers2

20

As indicated by the other replies, the slow-down is caused by the imap.so extension.

Looking deeper into this though, it appears that the reason why is that it's trying perform a DNS lookup for the local machine's hostname.

Adding your hostname to your /etc/hosts file should fix it:

me@mbp ~> hostname 
mbp.local

cat /etc/hosts
...
127.0.0.1     mbp.local
::1           mbp.local
...

Before:

me@mbp ~> time php -v
PHP 7.0.12 (cli) (built: Oct 24 2016 18:49:11) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
        **5.04 real**         0.01 user         0.01 sys

After:

me@mbp ~> time php -v
PHP 7.0.12 (cli) (built: Oct 24 2016 18:49:11) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
        **0.03 real**         0.01 user         0.00 sys

I discovered this by capturing the network traffic using Wireshark.

Pascal Roget
  • 793
  • 9
  • 12
  • I don't understand this answer. What exactly are you adding? Should the 'hostname' be an actual hostname. What is the 'me@mbp' part and where do I find the equivalent of this? I don't understand which bits of this code should be cut and pasted into the hosts file and which are specific? I'm new to MAMP etc. Thanks in advance. – pjk_ok Sep 23 '21 at 13:40
  • I'm having this problem too on MAMP 6.5 where it always takes 5 seconds to load a page with images on. Incredibly annoying. My Mac won't let me amend the hosts file either. – pjk_ok Sep 23 '21 at 19:42
12

Solved. For some reason -n was not removing the .ini files. Deleting the .ini file altogether solved the issue.

Some googling lead me to the extension causing the issue. I commented out the following line in my .ini file

; extension=imap.so
GWed
  • 15,167
  • 5
  • 62
  • 99
  • me too. After comment imap.so, problem solved. But I don't know why. Is there any clue? – Blade Oct 22 '16 at 09:39
  • 1
    yes, its trying to do a DNS lookup for the local hostname. Adding the relevant entries to your /etc/hosts file resolves the problem without disabling the module. – Pascal Roget Jan 25 '17 at 23:19