22

PHP runs so slowly on my Windows desktop that phpMyAdmin takes minutes to open a database. Here’s a comparison of the time to run a simple PHP test program:

  • Windows 8.1 machine running XAMPP: 3597 ms
  • iPage shared hosting: 65 ms
  • A2Hosting shared hosting: 26 ms

Here’s the test program…

<?php
$rStartTime = microtime(true);
$countTo = 100000;
$a = 0;
//$countTo = $countTo * 100;
for ($x = 0; $x <= $countTo; $x++) {
    $a = sqrt(pow($x, 2));
}
$rMs = floor((microtime(true) - $rStartTime) * 1000);
echo 'timer done, countTo=' . $a . ' ms=' . $rMs;

The test program is run without debugging, by entering "http://localhost/timer.php" into Firefox.

The local machine is normally blazing fast. It’s running…

  • Windows 8.1
  • XAMPP 1.8.3 (control panel v3.2.1)
  • Apache 2.4.4 (latest is 2.4.20)
  • PHP 5.5.3
  • Antimalware = Windows Defender
  • IDE = PHPStorm 10.0.2

What's making PHP run so slowly?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
CaptureWiz
  • 1,685
  • 1
  • 15
  • 15

12 Answers12

33

I found the problem was Xdebug in xampp\php\php.ini. Here're the results of trying many solutions found around the web:

Run XAMPP as adminisrator and restart server: 3617 ms

In xampp/apache/conf/httpd.conf, replace localhost with 127.0.0.1 and restart server: 3639 ms

In Windows/System32/drivers/etc/hosts, add “127.0.0.1 127.0.0.1” & “127.0.0.1 localhost” and restart Windows: 3960 ms

In Windows/System32/drivers/etc/hosts, un-comment “127.0.0.1 localhost” and restart Windows: 3659 ms

In php.ini, uncomment zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll" and restart server: 3643 ms

In php.ini, set xdebug.remote_enable=0: 3598 ms

In php.ini, set remote_host="localhost": 3593 ms

In php.ini, set xdebug.profiler_enable=0: 249 ms

In php.ini, comment out all Xdebug statements: 27 ms - Success!

The sad part is, I make mistakes and need Xdebug :-(

CaptureWiz
  • 1,685
  • 1
  • 15
  • 15
11

I solve my problem with xdebug idekey setting (xdebug.idekey="xdebug1"), and chrome extension xdebug helper (https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc)

*Dont forget to disable remote_autostart (xdebug.remote_autostart=0)

Only activating debug (xdebug) by request, using idekey setting, so if debug not needed php processing can be faster/normal, tonggle by button with chrome extension

I'm using xampp 1.8.3 on windows 10 64bit, i use custom idekey, xdebug.idekey="xdebug1", same with xdebug helper setting

[XDebug]
zend_extension = "E:\xampp183\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "E:\xampp183\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_autostart=0
xdebug.idekey="xdebug1"
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "E:\xampp183\tmp"
xdebug.remote_log="E:\xampp183\tmp\xdebug\xdebug.log"

setting1

enter image description here

enter image description here

Now breakpoint/debug activated only if session is requsted via xdebug helper

Nuha Dzikri
  • 570
  • 1
  • 7
  • 11
  • Thanks Dzikri for this imaginative and nicely detailed solution! I tested it and it did indeed speed things up 2X! But even with your tip, php ran slow :-( Normal time = 3597ms. With Dzikri tip, time reduced to 1482ms with debugging off, 1478 with debugging on (strangely faster!?). But by commenting out the Xdebug section in php.ini, the time is reduced to 27ms. – CaptureWiz Apr 14 '17 at 19:11
  • glad to help, maybe different local settings, different pc specs, so the result are variative, in my case, it can speed up to 90% if compared to letting xdebug autostart=on – Nuha Dzikri Apr 15 '17 at 12:41
  • 1
    This sped up my connection time on localhost from some 10-30 seconds to 2-4 seconds, which is a huge improvement, thanks! – Sean Kendle Feb 12 '21 at 16:09
  • one more, if you don't need profiling, make sure to turn off the the setting, can cause huge slowdown xdebug.profiler_enable = 0 xdebug.profiler_enable_trigger = 0 – Nuha Dzikri Feb 13 '21 at 03:50
  • In Xdebug 3, `xdebug.remote_autostart=0` becomes `xdebug.start_with_request=no` – KalenGi Mar 19 '23 at 09:06
10

I excluded my website folder and my xampp folder in Windows Defender and things were solved here.

Sebas
  • 21,192
  • 9
  • 55
  • 109
  • Thanks Carsten, that was a great idea I hadn't thought of! I tested it and it did indeed speed things up 2X! But even with your tip, it was slow :-( Normal time = 3597ms. With Carsten tip = 1509ms. Comment out Xdebug: 27ms. – CaptureWiz Apr 07 '17 at 13:15
  • Can you briefly explain how this is accomplished? – ju_ Oct 30 '17 at 18:24
  • 1
    Open Defender and go to Preferences/Settings ("Einstellungen" I use a german version here) and then excluded Files/Folders and there use the button to get a file dialog where you can point to your Files/Folders – Carsten Wartmann Nov 01 '17 at 09:27
  • I have tried everything but only this one worked. Thank you, man! You are a life saver. I excluded the entire xampp folder and page loading time reduced to < 1 sec from 15-20 sec. – Pankaj May 01 '19 at 14:09
2

I Had the same problem with xampp, and the problem was WINDOWS DEFENDER, if you disable the windows defender protection, xampp is faster (normal speed), Also you can search the xampp folder as exlusion in windows defender. these is the solution.

1

Running the TS (Thread Safe) version of php can slow things down a lot. TS is generally never needed, so use a NTS (Non-Thread Safe) version of php.

[Edit addition, stolen from Quora] Thread Safe (TS) and Non-Thread Safe (TS) are the two different PHP builds available.

Thread-safety ensures that when the shared data structure is manipulated by different threads, it is free from race conditions. This version is recommended where the web server run multiple threads of execution simultaneously for different requests.

For example, in Apache server, if we use mod_php as worker MPM, thread-safe version should be used.

Non-thread-safe version on the other hand is used where PHP is installed as a CGI binary. Here every request is handled separately which removes the need of thread-safe version. Moreover, using thread-safe version here degrade the performance due to unnecessary checks for thread safety. Servers like IIS & NGINX do not need thread safe versions.

Dakusan
  • 6,504
  • 5
  • 32
  • 45
  • That's a fabulous idea that nobody else has mentioned, thanks! How does one run the thread safe version? – CaptureWiz Nov 01 '22 at 23:09
  • If you are compiling PHP yourself, I believe the flag is either --enable-zts OR --enable-maintainer-zts, depending on your PHP version. If you are just downloading the binaries, you can choose which version. For example, for windows, the downloads are at https://windows.php.net/download/ . And on that page, it specifies if the version you are downloading is TS or NTS. – Dakusan Nov 03 '22 at 10:18
  • Thanks Dakusan, I'll test your suggestion when I get back to programming PHP, which won't be for a few months. – CaptureWiz Nov 04 '22 at 20:33
0

I figured out that Eclipse did not end a XDebug session properly. I solved the problem by restarting the debug session and ending it properly.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Zudi
  • 1
  • 3
  • How did you restart and end the XDebug session properly? – CaptureWiz Oct 03 '17 at 14:40
  • I guess I closed Eclipse without ending the XDebug session, which means I did not click the red box (terminate) in the menu. When I opened phpMyAdmin the next day it was slow a.f. Reopening Eclipse, starting a debug session and ending it properly by clicking the red box icon solved the problem. Since then I normally open phpMyAdmin in a different browser (chrome) than I do the debugging (Firefox) – Zudi Oct 04 '17 at 15:34
0

for me has been an improvement after changing all of above to change from https://localhost to https://127.0.0.1

Daniel D
  • 79
  • 1
  • 4
0

For chrome users: I found out (after trying all hints above) that the Chrome extension "Evernote Web Clipper" is also slowing down chrome. When loading a plain URL without any includes: enabled / disabled Evernote Web Clipper: 0,7ms / 0,25ms

Fuxi
  • 7,611
  • 25
  • 93
  • 139
0

For me, mcAfee Web boost extension was the Blocker. I removed the extension and now it speeds up by 90%

Neenu Chandran
  • 722
  • 1
  • 6
  • 18
0

If you are using mysql db within your PHP script, pls check your db connection config.

Use 127.0.0.1 instead of localhost in case of db host on windows (10).

  • Thanks, but no database modification can fix the underlying slowness of PHP. MySQL runs slow just like every other PHP program. In the speed tests above, I tried changing localhost to 127.0.0.1 in various other places, such as php.ini, and sadly, it never helped much. – CaptureWiz Mar 16 '21 at 03:27
  • I was facing very similar issues recently, and I also tried several tips and 'tricks'. The 'final' or current result (avg php script exection time) is not as bad (~usable for dev purpose), but still not as fast as it could be. Set the mysqli connection settings (localhost to 127.0.0.1) resulted about ten times acceleration. I also modified the 'ServerName' of the Apache httpd, modified the virtual hosts, etc, furthermore I turned of the IPv6 (network adapter settings), turned of/add exceptions for the Win Defender, but all of these amendments meant almost nothing. – qwaevisz Mar 17 '21 at 07:13
0

In case you are working with Xdebug 3 on Windows 10, you can build off the solution by Nuha Dzikri:

  1. Setup Xdebug Helper as described
  2. I'm not using profiling, so I left out the related config options (xdebug.profiler_*)
  3. Replace the following config options:

Xdebug 2

xdebug.remote_enable = 1
xdebug.remote_autostart=0
xdebug.idekey="xdebug1"
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"

with:

xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.idekey="xdebug1" #ineffective in trigger mode, but no harm leaving it in place
xdebug.trigger_value = "xdebug1" #works with start_with_request = trigger
xdebug.remote_handler = "dbgp"
xdebug.client_host = "127.0.0.1"
xdebug.client_port = 9003 # or 9000 if you want to continue using the legacy port

Refer to Upgrading from Xdebug 2 to 3 to replace other legacy config settings

I also excluded the C:\xampp folder from Windows Defender as suggested by Carsten Wartmann:

Start > Type "security" > Windows Security > Virus & threat protection > Manage settings > Exclusions > Add or remove exclusions > Add an exclusion > Folder > C:\xampp

KalenGi
  • 1,766
  • 4
  • 25
  • 40
  • Thanks KalenGi, that's great info! Could you please run the test program above to see how fast PHP runs with Xdebug 3? – CaptureWiz Mar 21 '23 at 00:33
-1

Solved php - WAMP/XAMPP is responding very slow over localhost / wordpress

The easiest way is that go to c dirive > xamp > php folder > search php.ini > clink on top then find max_execution_time anset it to max_execution_time=300 > now restart xamp > all done :)

max_execution_time=300
Ashar Zafar
  • 382
  • 2
  • 11
  • Thanks, but while this may have solved your problem, it didn't solve mine. I had already increased max_execution_time from the default value of 30 sec to 10 hours (36000 sec), and PHP still ran terribly slow. – CaptureWiz Oct 03 '17 at 14:29
  • set max_execution_time=300 maybe your site cache issue i set max_execution_time=300 it's working fine – Ashar Zafar Oct 04 '17 at 07:26