Win7 上的 XAMPP 太慢
我在 Windows 7 Ultimate 上运行 XAMPP 1.7.1。除了速度之外,一切(Apache 和 MySQL)都工作正常。
当我打开 http://localhost/ 时,我必须等待大约 1-3 秒才能查看网页。在我看来,最多应该是几百毫秒。
基本事实:
- 在等待加载本地主机网页时,状态栏显示“正在等待本地主机...”
- 本地主机上的CPU 仍然空闲(加载时没有增加活动)
- 没有要求很高的 PHP 脚本,问题出在简单的 phpinfo() 上即使有又长又重的脚本。
- 禁用 MySQL 服务器不会影响
- 我的 PC 的速度:AMD Turion 64 X2; 1,6 GHz 双核、2 GB RAM、100 GB HDD
我制作了一个简单的基准 PHP 脚本来测试 HDD/CSS 速度:
<?php
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function testReadWrite() {
$timeStart = getmicrotime();
$filename = "test.txt";
file_put_contents( $filename, '' ); // prepare empty file
for ( $i = 0; $i < 1000; $i++ ) {
$a = file_get_contents( $filename );
file_put_contents( $filename, $a . '.' );
}
return round( getmicrotime() - $timeStart, 3 );
}
function testCpuSpeed() {
$timeStart = getmicrotime();
$var = '';
for ( $i = 0; $i < 100000; $i++ ) {
$var = sha1( md5( $i * $i * $i * $i * $i * $i * $i * $i * $i * $i ) );
}
return round( getmicrotime() - $timeStart, 3 );
}
echo "Read/write #1: " . testReadWrite() . "<BR>";
echo "Read/write #2: " . testReadWrite() . "<BR>";
echo "Read/write #3: " . testReadWrite() . "<BR>";
echo "CPU speed #1: " . testCpuSpeed() . "<BR>";
echo "CPU speed #2: " . testCpuSpeed() . "<BR>";
echo "CPU speed #3: " . testCpuSpeed() . "<BR>";
?>
我的 PC 结果:
- 读/写:5.134 / 3.431 / 3.494
- CPU 速度:0.816 / 0.767 / 0.795
虚拟主机结果:
- 读/写:7.768 / 7.69 / 7.371
- CPU 速度:0.232 / 0.234 / 0.234
我的服务器结果之一(空闲计算机几乎与我的 PC 相同,但速度更快一点):
- 读/写:0.088 / 0.168 / 0.185
- CPU速度:0.191 / 0.189 / 0.189
所以我不认为这是因为我的PC速度,但我确信还有其他问题。 您对 Windows 7(或 Vista)上的 XAMPP 速度有一些经验吗?
谢谢。
I'm running XAMPP 1.7.1 on Windows 7 Ultimate. Everything (Apache & MySQL) is working fine except for speed.
When I open http://localhost/, I must wait probably 1-3 seconds for view a webpage. In my opinion, it should be at most some hundreds miliseconds.
Basic facts:
- while waiting to load a localhost webpage, status bar says "Waiting for localhost..."
- CPU is still idle (no increased activity while loading)
- on localhost is no demanding PHP scripts, problems are when there is simple phpinfo() even if there is long heavy scripts.
- disabling MySQL server don't affect speed
- my PC: AMD Turion 64 X2; 1,6 GHz dual-core, 2 GB RAM, 100 GB HDD
I've made a little simple benchmark PHP script to test HDD/CSS speeds:
<?php
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function testReadWrite() {
$timeStart = getmicrotime();
$filename = "test.txt";
file_put_contents( $filename, '' ); // prepare empty file
for ( $i = 0; $i < 1000; $i++ ) {
$a = file_get_contents( $filename );
file_put_contents( $filename, $a . '.' );
}
return round( getmicrotime() - $timeStart, 3 );
}
function testCpuSpeed() {
$timeStart = getmicrotime();
$var = '';
for ( $i = 0; $i < 100000; $i++ ) {
$var = sha1( md5( $i * $i * $i * $i * $i * $i * $i * $i * $i * $i ) );
}
return round( getmicrotime() - $timeStart, 3 );
}
echo "Read/write #1: " . testReadWrite() . "<BR>";
echo "Read/write #2: " . testReadWrite() . "<BR>";
echo "Read/write #3: " . testReadWrite() . "<BR>";
echo "CPU speed #1: " . testCpuSpeed() . "<BR>";
echo "CPU speed #2: " . testCpuSpeed() . "<BR>";
echo "CPU speed #3: " . testCpuSpeed() . "<BR>";
?>
My PC results:
- Read/write: 5.134 / 3.431 / 3.494
- CPU speed: 0.816 / 0.767 / 0.795
A webhosting results:
- Read/write: 7.768 / 7.69 / 7.371
- CPU speed: 0.232 / 0.234 / 0.234
One of my server's results (as idle computer nearly as my PC, but a little bit faster):
- Read/write: 0.088 / 0.168 / 0.185
- CPU speed: 0.191 / 0.189 / 0.189
So I don't think that it is because of my PC speed, but I'm sure that there's some another problem.
Do you have some experience with XAMPP speed on Windows 7 (or Vista) ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
如果 XAMP 在 Windows 7 下运行缓慢,则防火墙设置没有影响。
Security Essentials 防病毒软件没有什么区别。
为了解决这个问题,两个有很大区别的事情是:
1) 在 windows\system32\drivers\etc\hosts 中添加以下行:
127.0.0.1 127.0.0.1
127.0.0.1 localhost
2) 如果您使用 PHP ,在 XAMP php.ini 文件中取消注释 eaccelerator 行:
zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll"
在这两个更改之后,重新启动 Apache,速度会快得多。
If XAMP is slow under windows 7, the firewall settings make no difference.
The Security Essentials anti-virus makes no difference.
To solve this problem, the two things that make a big difference are:
1) in windows\system32\drivers\etc\hosts add the following lines:
127.0.0.1 127.0.0.1
127.0.0.1 localhost
2) If you're using PHP, in the XAMP php.ini file uncomment the eaccelerator line:
zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll"
After these two changes, restart Apache and it will be way faster.
不确定这可能是您问题的原因,但这可能是一个想法:
您的主机中是否有一行看起来像这样的行:(它应该位于类似
C:\WINDOWS\system32\ drivers\etc\hosts
,如果我没记错的话) 文件?如果是,请在开头添加
#
来注释该行。这样,关于 localhost 的唯一一行应该
是 IPv4 地址;你评论的那个是 IPv6——这对你想做的事情来说毫无用处。
正如我所说,不确定您的问题是否与此相关,但我已经看到此建议多次帮助解决与您的问题非常相似的问题(即在服务器上执行任何操作之前等待很长时间)。
Not sure this might be the cause of your problems, but this might be an idea : do you have a line that looks like this :
in your hosts (it should be somewhere like
C:\WINDOWS\system32\drivers\etc\hosts
, if I remember correctly) file ?If yes, comment that line by adding a
#
at the beginning.This way, the only line that's about localhost should be
which is an IPv4 address ; and the one you commented being an IPv6 -- which is quite not useful for what you are trying to do.
As I said, not sure your problem is related to this, but I've seen this sugestion help a couple of times for problems quite similar to your (i.e. waiting a long time before doing anything on the server).
使用 XDEBUG 注释 PHP.ini 中的行:
最好的问候
巴托
Comment the lines in PHP.ini with XDEBUG:
Best regards
Barto
我在 Win 7 + XAMPP 上也遇到了类似的问题。该问题是由我的防病毒软件引起的。启用后,即使是最简单的 PHP 页面也需要半秒以上的时间才能打开。具有大量链接的 require_once() 的大型 PHP 脚本花费了超过 1.5 秒。禁用防病毒功能后,一切都快如闪电(每个简单页面不到 100 毫秒,真正繁重的内容大约需要 500 毫秒(100 多个链接的 require_once()))。
我正在使用 bitdeffender,这里是它的解决方案:
游戏模式
- 转到防病毒 ->盾牌->高级设置->排除选项卡
并添加 httpd.exe 的排除(位于您的 xampp 安装/apache/bin/ 中)。然后转到防病毒 ->排除
并为 php 文件所在的目录添加排除。完成上述步骤后不要忘记重新启动 apache。
您可以选择安装 eaccelerator 以进一步加快速度。
正如我附注的:我发现 WAMP 作为一个项目不如 XAMPP 成熟。
旁注 2:最好的解决方案是使用您的旧 PC 作为 Linux 服务器,一切都会像魅力一样工作:-)
I had similar issue with Win 7 + XAMPP. The problem was caused by the my antivirus software. When it was enabled even simplest PHP page was taking more than half a sec to open. Big PHP scripts with a lot of chained require_once()s tooked more than 1,5 seconds. With antivirus disabled everything was lightening fast (less than 100 miliseconds per simple pages, and about 500 miliseconds for really heavy stuff (100+ chained require_once())).
I am using bitdeffender and here is the solution for it:
game mode
when working with xamppAntivirus -> Shield -> Advanced Settings -> Exclusions Tab
and there add exclusion for httpd.exe (located in your xampp installation/apache/bin/). Then go toAntivirus -> Exclusions
and add exclusion for the directory where your php files reside.Don't forget to restart apache after above steps.
Optionally you can install eaccelerator to speed the things even more.
As I side note: I found WAMP less mature as a project than XAMPP.
Side note 2: The best solution is to use your old PC as linux server and everything will work like a charm :-)
阅读了几个答案后 - 它们都没有帮助(我什至删除了我的防病毒软件)。
对我有很大帮助的是禁用 xdebug。现在一切都变得非常快。
After reading several answers - non of them helped (I even removed my antivirus).
What helped me dramatically is disabling xdebug. Now everything became very fast.
有两件事可能导致此问题。防病毒软件和主机文件中的设置
1) 在 windows\system32\drivers\etc\hosts 中添加以下行:
127.0.0.1 127.0.0.1
127.0.0.1 localhost
2) 在防病毒软件中,排除 document_root包含您的文件的文件夹(例如 c:/www 或 c:/xampp/htdoc 等)。要测试这一点,您还可以暂时禁用防病毒软件,但长期修复方法是排除文件夹和子文件夹
Two things can cause this issue.Anitivirus software and the settings in hostfile
1) in windows\system32\drivers\etc\hosts add the following lines:
127.0.0.1 127.0.0.1
127.0.0.1 localhost
2) In your antivirus, exclude the document_root folder that contains your files (eg c:/www or c:/xampp/htdoc etc). To test this, you can also disable your anti virus temporarily but long term fix is to exclude the folder and subfolders
我的 BUG - XAMPP 非常慢
我的 Xampp 速度变慢并最终停止是由填充 php 日志的警告消息引起的 - 继续阅读
1 - Localhost/127.0.0.1 - 无帮助
2 - 病毒软件干扰 - 无帮助
3 - 端口干扰更改为 8080 - 没有帮助
4 - Wamp - 同样的事情 - 没有帮助
最终事情完全失败,出现 500 个错误。
C:\xampp\php\logs\php_error_log 几乎是一个 MB (957K),
对于 notepad++ 来说太大了(我的第一个线索),而记事本需要几分钟才能渲染。
数千条“严格”和“警告”类型的消息
FIX
更改了 php.ini
display_errors=On to =Off “那里还有其他几个错误开/关开关,但这一个为我做到了。”
nenamed log
重新启动了 apache 和 mysql
生活很好。
My BUG - XAMPP VERY SLOW
My Xampp slow down and eventual stop was caused by warnings messages filling the php log - read on
1 - Localhost/127.0.0.1 - no help
2 - Virus software interference - no help
3 - Port interference changing to 8080 - no help
4 - Wamp - same thing - no help
eventually things failed altogether with 500 errors.
C:\xampp\php\logs\php_error_log was almost a MB (957K)
too big for notepadd++ (my first clue I was on to something) and notepad took several minutes to render.
Thousands of messages of the "Strict' & 'Warning' type
FIX
changed the php.ini
display_errors=On to =Off "There are several other error on/off switches in there, but this one did it for me."
nenamed log
restarted apache and mysql
Life is good.
尝试一下 Wamp Server 怎么样?
与 XAMPP (44mb) 相比,安装文件要小得多 (16mb)。
http://wampserver.com/
How about giving Wamp Server a try?
The installation file is a lot smaller (16mb) compare to XAMPP (44mb).
http://wampserver.com/
在 C:\WINDOWS\system32\drivers\etc\hosts 中,我对这些行进行了注释
,并添加了大约 100 行其他规则。
解决方案是删除所有这些规则或取消注释
127.0.0.1 localhost
并将其放在顶部。In
C:\WINDOWS\system32\drivers\etc\hosts
I had these lines commentedand around 100 more lines of other rules.
The solution is to erase all those rules or to uncomment
127.0.0.1 localhost
and put in on top.使用 127.0.0.1 而不是“localhost”连接到数据库对我有用。
但我搜索了另一个解决方案并提出了这个:
在您的 my.ini 文件中,取消注释以下行:
您最终会得到:
重新启动您的 mysql 服务器,并且页面应该加载得非常快,而无需2-3秒延迟。
此外,使用此解决方案,您不需要修改数据库连接代码中的连接,您可以继续使用“localhost”而不是“127.0.0.1”
Connecting to the DB using 127.0.0.1 instead of "localhost" worked for me.
But i searched for another solution and came up with this:
In your my.ini file, uncomment the following line:
You'll end up having:
Restart your mysql server and pages should load very fast without the 2-3 second delay.
Also, with this solution you don't need to modify your connection in your DB connect code, you can continue using "localhost" instead of "127.0.0.1"
冒着陈述显而易见的风险——检查主机文件的大小。由于 Spybot 为曾经存在的每个恶意软件站点添加了例外,我的主机文件已经膨胀到 450K,即使这些站点大多不再活跃。 Spybot 对这 10000 多个条目进行了评论,版权日期为 2008 年,无论如何,它们都毫无用处。
我不知道其他间谍软件防护软件是否这样做,但主机文件应该足够小,以便 XAMPP 不必在每次显示页面时都通过异常 URL 进行切换。顺便说一句,如果您安装了任何破解软件(我当然不会容忍这种情况),请小心不要删除阻止在线验证检查站点的主机例外。
At the risk of stating the obvious -- check the size of your hosts file. My hosts file had ballooned to 450K due to Spybot adding exceptions for every malware site that ever existed even though those sites were mostly no longer active. Spybot commented these 10000+ entries with a copyright date of 2008, making them useless anyway.
I don't know if other spyware protection software does this, but the hosts file should be small enough so that XAMPP doesn't have to churn through the exception URLs every time it displays a page. BTW if you have any cracked software installed, which I don't condone of course, be careful not to delete the hosts exceptions that block online validation checking sites.
一年前我遇到了同样的问题,终于找出了问题所在。
如果您的日志(访问、错误)文件非常大,即使使用记事本打开也需要一些时间怎么办?
是的,你没听错,xampp 会创建这些文件。
现在,如果我们有问题,那么也有解决方案。
我们可以每天轮换日志文件。步骤如下
CustomLog "logs/access.log" common
CustomLog "|bin /rotatelogs.exe logs/access_%y-%m-%d.log 86400" common
我也同意 disble Xdebug 也会有帮助。
i had same issue year back ago and finally find out what makes problem here.
what if your log (access,errors) files are going to such a huge that it will a take time to open even with notepad?
yes, you heard right xampp will create those files.
Now If we have problem then there is solution too.
we can rotate log files for every day. here is steps
CustomLog "logs/access.log" common
CustomLog "|bin/rotatelogs.exe logs/access_%y-%m-%d.log 86400" common
i also agree with disble Xdebug will help too.
这就是我所做的,它使 XAMPP 方法更快:
在主机文件 (C:\Windows\System32\drivers\etc\hosts) 中为我的站点分配一个新的且未使用的环回地址。换句话说,我避免使用用于其他站点的 127.0.0.1:
127.0.0.2 example.com
在 Apache httpd.conf 文件中添加:
Listen 127.0.0.2: 80
因为我有几个站点,我在每个站点的 htdocs 下都有子文件夹。在此示例中,文件夹名称是 example.com,这就是我的网站所在的位置。因此,再次在我的 httpd.conf 文件中添加了一个 VirtualHost,如下所示:
<代码><虚拟主机 127.0.0.2:80>
ServerAdmin [电子邮件受保护]
文档根目录“C:/xampp/htdocs/example.com”
服务器名称 example.com
错误日志“c:/xampp/apache/logs/example.log”
CustomLog“c:/xampp/apache/logs/example-access.log”常见
重新启动 Apache。
之后,在浏览器中访问 example.com 加载速度非常快。
This is what I did and it made XAMPP ways faster:
Assigned a new and unused loopback address to my site in the hosts file (C:\Windows\System32\drivers\etc\hosts). In other words I avoided using 127.0.0.1 used for other sites:
127.0.0.2 example.com
In the Apache httpd.conf file added:
Listen 127.0.0.2: 80
As I have several sites, I have subfolders under htdocs for each site. In this example the foldername is example.com, and that is where my site sits. So added a VirtualHost, again in my httpd.conf file, like so:
<VirtualHost 127.0.0.2:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs/example.com"
ServerName example.com
ErrorLog "c:/xampp/apache/logs/example.log"
CustomLog "c:/xampp/apache/logs/example-access.log" common
</VirtualHost>
Restarted Apache.
After that, visiting example.com in the browser loads really quick.
我有同样的问题......
我所做的是卸载了
C: 驱动器
上的 xampp 。将其安装到另一个驱动器
(E:)
...并且不知道,但它工作正常且快速....
I have same problem....
What I did is I uninstalled xampp which was on
C: drive
.Installed it onto another drive
(E:)
...and dont know but its working fine and fast....
我使用 Avast 防病毒软件,只需单击一下即可解决问题。右键单击 Avast 图标并选择静音/游戏模式。就这样。
I use Avast antivirus and solved the problem with a simple click. Right-click the Avast icon and select Silent/gaming mode. That's all.
我遇到了这个问题,它与防病毒或防火墙无关。通过确保本地主机正在寻找 127.0.0.1,可以轻松修复该问题。
我在这里找到了很好的建议:
[http://www.devside.net/wamp-server/ wamp-is-running-very-slow
说明如下:
编辑文件 –
C:\Windows\System32\drivers\etc\hosts
通过在前面添加“#”注释掉该行:::
1 localhost
如果“localhost”解析为 IP 地址“::1”,则请求(当无法解析时)查找 IPv6 侦听套接字)将被路由回 IP 地址 127.0.0.1(通过超时、回退或某些其他机制),从而导致不必要的连接延迟(例如,通常为 1 秒到 30 秒)。
确保“localhost”正确映射到 IPv4 环回地址“127.0.0.1”(...该行未被注释掉):
127.0.0.1 本地主机
i had this problem, it was not related to anti-virus or firewall. was easily fixed by ensuring local host was looking for 127.0.0.1.
i found good advice here:
[http://www.devside.net/wamp-server/wamp-is-running-very-slow
the instructions were as follows:
Edit file –
C:\Windows\System32\drivers\etc\hosts
Comment out the line by adding a ‘#’ in front:
::1 localhost
If “localhost” gets resolved to IP address “::1″, the request (when not able to find an IPv6 listening socket) will get routed back to IP address 127.0.0.1 (via timeout, fall-back, or some other mechanism), causing unnecessary delays for connections (e.g., typically anywhere from 1 second to 30 seconds).
Make sure that “localhost” is correctly mapped to the IPv4 loopback address “127.0.0.1” (…that this line is not commented out):
127.0.0.1 localhost