13

When I make local changes to my PHP / WordPress website, the localhost does not seem to update for 20-30 minutes.

I'm on Mac OSX 10.8.4 and using MAMP Pro. I have two sites that I have created separate host entries for, let's call them mysite1.dev and mysite2.dev.

Here is my MAMP Server configuration:

Apache: 80
MySQL: 3306
SSL: 443

I saw this article ( How can I eliminate slow resolving/loading of localhost/virtualhost (a 2-3 second lag) on Mac OS X Lion? ) on the Bonjour conflicts and edited my /private/etc/hosts file with the suggestions in this article:

  1. I changed the host names from mysite1.localhost to mysite.dev because it sounds like the conflict is with .local names - DID NOT WORK

  2. I updated the Hosts file to have separate ::1 addresses - DID NOT WORK:

    ::1 <tab> mysite1.dev
    ::1 <tab> mysite2.dev
    
  3. I tried putting all of my host entries onto one line - also didn't work:

    127.0.0.1 localhost mysite1.dev mysite2.dev
    ::1 localhost
    fe80::1%lo0 localhost
    

It seems like MAMP Pro overwrites the hosts file any time I restart the server.

I would be SUPER grateful for any help you can offer.

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
user2733720
  • 131
  • 1
  • 1
  • 3
  • Im not sure if this will help, but its a suggestion :-) Try and clear all cache you can find attached to your browser. Also try to totally reinstall your MAMP server. Remember to take backup. – Daniel Aug 30 '13 at 16:53
  • http://stackoverflow.com/questions/8452614/mamp-reloading-pages-is-very-slow found this aswell.. check it out.. idk if it helps, if it does im happy :-) – Daniel Aug 30 '13 at 16:54
  • This sounds like a WordPress caching issue, not a database thing. Have you looked in the WordPress database to see if the content changes have applied? Next step: Turn off plugins to isolate the problem. – tadman Aug 30 '13 at 16:59
  • After upgrading php to 5.5 in MAMP, for some obscure reason, OPCache is enabled by default. This makes the server return cached versions of pages instead of the newer versions (with your changes). I followed [instructions from this thread](http://stackoverflow.com/a/19130992/1200166) to disable OPCache. – rantebi Feb 03 '14 at 08:23

12 Answers12

17

Change MAMP cache to OPcache. It worked for me enter image description here

shamila
  • 1,280
  • 6
  • 20
  • 45
  • 10
    Using OPcache during development is no good idea. Normally you disable all caching during development. Otherwise you have to wait ages until your latest changes are reflected on the site. – leymannx May 23 '19 at 08:53
7

I had the same problem and found the solution on this post: MAMP time between seeing live changes

The instructions, which I followed:

The solution is uncommenting lines in the php.ini file, which can be found in

/{MAMP Directory}/bin/php/php5.5.3/conf/php.ini

Comment out Opcache:

[OPcache]
;zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
;  opcache.memory_consumption=128
;  opcache.interned_strings_buffer=8
;  opcache.max_accelerated_files=4000
;  opcache.revalidate_freq=60
;  opcache.fast_shutdown=1
;  opcache.enable_cli=1

Documentation ( yes it started in 5.5 ):

http://www.php.net/manual/en/intro.opcache.php

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
WaZzo
  • 131
  • 2
  • 6
  • 2
    Using OPcache during development is actually no good idea. While your site may load a little bit faster you have to hit reload much more often until you see the current changes you made. – leymannx May 23 '19 at 08:42
4

I've been struggling with this issue ever since switching to SSL for my local environment (thanks, Salesforce API) and finally found a solution that worked for me:

Disable Xdebug

Turning off Xdebug cut TTFB from 25 seconds to 2. Yeesh.

Tammy Shipps
  • 865
  • 4
  • 13
3

I had similar problems running php 5.5.3. After I changed back to 5.4.19 it worked.

You can change the version in the MAMP GUI. You might have to rename your 5.5.3 folder to 5.5.X for 5.4.19 to show up in the GUI. The php folders are placed at: Applications/MAMP/bin/php

Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
3

For me, changing back to MAMPS standard port settings did the trick.

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
3

I was having same issue, I had added virtual host ending with .local which was causing 5 seconds delay in lookup.

To fix this I updated host file.

sudo nano /etc/hosts

And added my site with IPv6 address along with ::1 and 127.0.0.1.

::1             mysite.local
127.0.0.1       mysite.local
fe80::1%lo0     mysite.local
VK321
  • 5,768
  • 3
  • 44
  • 47
2

The solution that worked for me was to turn off Xdebug as @tammy-shipps mentioned. However since I have the vanilla MAMP version, I had to turn off Xdebug with the php.ini file found here:

/{MAMP Directory}/bin/php/{PHP Version}/conf/php.ini

Then change xdebug.remote_enable from 1 to 0:

xdebug.remote_enable=0

Unlike other proposed solutions, turning off cache or changing ports had no affect on the problem.

Frank
  • 83
  • 1
  • 6
1

MAMP's default ports are non-standard. When I switched to standard ports (80 for Apache & 443 for SSL), it sped up dramatically.

I'm not sure if this is what Paul Bakker did, or if he switched the other way.

I'm using MAMP Pro 4.2, PHP 7.1.6, Apache, OS X 10.11.6.

photocurio
  • 146
  • 11
1

It was really hard, but I found a solution that it works in my environment:

  • MAMP 4.2.1
  • PHP 5.6.31

SETTINGS left menu > Ports settings > Run servers as: > Change it to "Unix Users" option.

enter image description here

M_iserte
  • 98
  • 5
  • I did this and now when I browse to any page it says "... isn't writable by PHP. Please fix that." What else did you do if anything? – Steven Thate Aug 31 '19 at 16:38
  • Hey @StevenThate. I didn't do anything else but it seems a permission problem. Since the answer is one year old, I would look for the isolated error since it is possible you're using a new Mac OS or MAMP version. By the way, it seems a permission error, try to reset permissions on your site. – M_iserte Sep 03 '19 at 07:14
  • Thanks. Turns out updating MAMP from 5.1 to 5.4 fixed my performance issues. – Steven Thate Sep 04 '19 at 14:19
  • I'm on Mac Big Sur, and I tried this, and while the pages load fast, they fail due to Apache not having permission to write to a log file specified by the PHP code. Since I work with many repos that I mostly didn't write, I don't care to go down this rabbit hole, so I'm switching back until I find a better solution. – SteveExdia Jul 16 '21 at 15:13
1

Setting xdebug.remote_host to to 127.0.0.1 instead of "localhost" solved this issue for me. This skips IPV6 resolution, which caused the delay.

Switching off remote_enable is not an option, because it kills debugging in PHPStorm:

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
0

I'm not sure about Mamp, however, I use php -S 0.0.0.0:4444 to spin up a local server. Its response got very slow after moving to Mojave.

I was able to fix it by updating /etc/hosts file with

::1             localhost YouMacName.local
127.0.0.1       localhost YouMacName.local

You can get YourMacName.local by running in terminal:

$ hostname
hemanto
  • 1,900
  • 17
  • 16
0

Switch off the PHP-Cache as shown below screenshot.

enter image description here Below in the screen shot you can see

Jay Bharat
  • 691
  • 7
  • 6