1

I am dealing with really slow loading of pages. I used Chrome console's Network tab to get this information (but it is slow on all browsers).

I have researched the issue heavily, but now I am completely stumped. I have tried Blowski's answer to MAMP: reloading pages is very slow (editing my hosts file), but had no luck with getting the page to load faster.

I am running OS X 10.8.5, CodeIgniter 2.1.3, and connecting to a remote MySQL database (which is on the same server as the live web server). Not sure if that has anything to do with the waiting being so long. Speed tests for loading the same page are below:

localhost
Waiting time is 13.49 seconds

enter image description here

Web Server
Waiting time is 222 milliseconds

enter image description here

What can I do to fix this issue?

Update: I've narrowed down the issue to the MySQL database (which is located on a remote server, separate from where PHP (MAMP) is installed). Are there any settings I would need to change to fix this horrible load time? I am also connecting to the database using an IP address and not a domain name, so I don't believe it is a DNS issue with the server MySQL is installed on.

Community
  • 1
  • 1
doitlikejustin
  • 6,293
  • 2
  • 40
  • 68
  • What does "10 minutes away" mean in terms of the connection? Are the PHP and MySQL machines in the same data center? – AllInOne Oct 04 '13 at 19:35
  • I just mean that the MySQL server is close. It's not on the other side of the country. PHP and MySQL are in the same data center only on web server, not on localhost. – doitlikejustin Oct 04 '13 at 19:40
  • For the purposes of this question, PHP is running on your local machine, connecting to a MySQL database at a remote location -- correct? What kind of connection is there between these applications? That is why you are running slow. For every page request there may be dozens of *sequential* round trips as data moves back and forth between PHP and MySQL. The solution would be to run a local copy of MySQL or somehow reduce the network congestion between your data and applications layers. – AllInOne Oct 04 '13 at 19:57
  • You are correct. I understand your suggestion, but what doesn't make sense to me is why is this happening only locally? I have a website running a MySQL database on a web server and it is running fine and have done with many times before running PHP/MySQL on different servers. Is there something different about "local" PHP? – doitlikejustin Oct 04 '13 at 20:05
  • Did you ever find a solution this? – Mike Jun 12 '15 at 12:08
  • No I did not. I ended up using a different computer – doitlikejustin Jun 13 '15 at 05:09

3 Answers3

1

For a general solution, try using a profiler - it is meant for diagnosing performance issues.

this link has a pretty good tutorial - http://geek.michaelgrace.org/2011/08/xdebug-cachegrind-and-mamp-on-mac-osx/

You should examine the results to see which function(s) take the most time of execution. I suspect your remote database connection may be at fault, but a profiler will give you definitive results.

xiankai
  • 2,773
  • 3
  • 25
  • 31
  • This didn't answer my question, but I am accepting it because it helped lead me to the source of the issue (which is still not solved) It boils down to long waiting for MySQL connections/queries. – doitlikejustin Oct 09 '13 at 05:03
0

Such a long lag makes me suspect profiling as the culprit, especially since it's only on localhost.

Check your php.ini if xdebug is enabled (it may be found in a separate xdebug.ini), and if so, if xdebug.profiler_enable is set to true/1.

That, or perhaps MAMP uses another profiler.

xiankai
  • 2,773
  • 3
  • 25
  • 31
  • Thanks for the answer. I tried adding it in my master php.ini and local php.ini as well as using `ini_set` but no luck in fixing the issue :( – doitlikejustin Oct 05 '13 at 16:56
  • I didn't meant to set it to true (thus enabling it), I meant that if it was present, that could be the cause of the lag. Perhaps you could try setting it to false instead? – xiankai Oct 05 '13 at 18:15
  • Oh I see. Well by default it was off, I manually set it to false though but still not working. – doitlikejustin Oct 05 '13 at 20:27
  • I've updated the question. Figured out it is my connection to the remote MySQL database... not sure if you have any other ideas. – doitlikejustin Oct 06 '13 at 21:01
0

Could it be that the server running the MySQL daemon is configured to do reverse DNS lookups? With the development machine being your own computer on a standard ISP line this could cause a serious delay on each request, as the reverse DNS lookup has to time out every time.

arnekolja
  • 1,687
  • 5
  • 22
  • 29