apache PHP 突然变得超级慢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1574526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP is suddenly super slow
提问by jzp74
I'm working on a web application using PHP, Apache, and MySQL. For the past year the response times of this application have been good. Suddenly yesterday the application became very slow on Firefox (complete page load, including CSS and JavaScript files: around 20 seconds. During page load, Firefox is completely unusable). Interestingly the response times in Internet Explorer were a bit slower (around 2 seconds instead of <1 second).
我正在使用 PHP、Apache 和 MySQL 开发 Web 应用程序。在过去的一年里,这个应用程序的响应时间一直很好。昨天突然,Firefox 上的应用程序变得非常慢(完整的页面加载,包括 CSS 和 JavaScript 文件:大约 20 秒。在页面加载期间,Firefox 完全无法使用)。有趣的是 Internet Explorer 中的响应时间有点慢(大约 2 秒而不是 <1 秒)。
The strange thing is: The application worked fine two days ago and out of nowhere became very slow. I didn't change anything in the sourcecode. I didn't change a thing in php.ini or httpd.conf. I already log the response times of PHP functions, and that performance hasn't changed.
奇怪的是:应用程序两天前运行良好,突然变得非常缓慢。我没有更改源代码中的任何内容。我没有更改 php.ini 或 httpd.conf 中的任何内容。我已经记录了 PHP 函数的响应时间,并且性能没有改变。
At first I thought it had something to do with Firefox, so I completely removed Firefox, restarted Windows Vista and did a clean install of Firefox (without extensions). No result.
一开始我还以为是 Firefox 的问题,所以我彻底卸载了 Firefox,重新启动了 Windows Vista 并全新安装了 Firefox(没有扩展)。没有结果。
After testing several things I found out that when I copy the application data to another folder in my document root, the application works fine again. Problem is solved you could think, but it's very annoying that I now have to use another URL and (more important) I don't get it. Why is my application very very very slow in one folder and perfectly fine in another folder?
在测试了几件事后,我发现当我将应用程序数据复制到文档根目录中的另一个文件夹时,应用程序又可以正常工作了。问题已经解决了,您可以想到,但是我现在必须使用另一个 URL 并且(更重要的是)我不明白这很烦人。为什么我的应用程序在一个文件夹中非常非常慢,而在另一个文件夹中却完全正常?
Does it have something to do with Firefox or with Apache? The name of the folder in which the application is very slow does not appear in either php.ini or httpd.conf.
它与Firefox或Apache有关吗?应用程序很慢的文件夹名称不会出现在php.ini 或httpd.conf 中。
回答by Ken Keenan
Some suggestions:
一些建议:
Install Fiddleron the client. This will allow you to analyse the low-level HTTP traffic coming from the server.
Extract some of the queries from your PHP code and run them interactively in the MySQL client and see if they're running slowly.
Log into the server (or get a system administrator if you don't have access) and run the Task Manager (Windows) or
top(Unix) and make sure there's nothing else hogging the server. If you haven't changed anything, maybe something else has changed on the server. Also, check the server logs/ Event Viewer.There is a Zendextension called APDthat you can install on the server (again, assuming you have rights), and it will profile your PHP code and write out a file showing what functions are being called by your PHP scripts are how long PHP is spending in each function.
在客户端安装Fiddler。这将允许您分析来自服务器的低级别 HTTP 流量。
从您的 PHP 代码中提取一些查询,并在 MySQL 客户端中以交互方式运行它们,看看它们是否运行缓慢。
登录服务器(如果您没有访问权限,请联系系统管理员)并运行任务管理器 (Windows) 或
top(Unix) 并确保没有其他东西占用服务器。如果您没有更改任何内容,则可能服务器上的其他内容已更改。此外,检查服务器日志/事件查看器。有一个名为APD的Zend扩展 ,您可以在服务器上安装它(同样,假设您有权限),它将分析您的 PHP 代码并写出一个文件,显示您的 PHP 脚本正在调用哪些函数是 PHP 的长度在每个功能上花费。
回答by Jeff Ober
Look for areas that might cause blocking, like shelling out to curl or opening a file over NFSin the code. If the remove system is timing out, it will drastically affect Apache performance as each request ties up the server for however many seconds it takes to time out and fail the lagging request.
查找可能导致阻塞的区域,例如在代码中进行卷曲或通过NFS打开文件。如果删除系统超时,它将极大地影响 Apache 的性能,因为每个请求都会占用服务器多长时间才能超时并使滞后请求失败。
回答by Henrik Opel
Did you change any network settings in your development setup recently? If so, you might encounter one of Mozillas IPv6 bugs. See this blog entry(taken from this question & answers) for details, and this mozillaZine articlefor more details and a quick option to test it.
您最近是否更改了开发设置中的任何网络设置?如果是这样,您可能会遇到Mozillas IPv6 错误之一。有关详细信息,请参阅此博客条目(取自此问题和答案),以及此 mozillaZine 文章以了解更多详细信息和测试它的快速选项。
回答by Black
I had the same problem. Suddenly even simple sites took about 5 minutes to load.
我有同样的问题。突然之间,即使是简单的网站也需要大约 5 分钟才能加载。
Cause:
原因:
Bad setting in my php.ini
我的设置不好 php.ini
I had to remove this line (or set it to off):
我不得不删除此行(或将其设置为关闭):
xdebug.remote_autostart=on
Then restart your webserver service.
然后重新启动您的网络服务器服务。
回答by nino_701
Make sure you didn't forgot the $ signe before any variable inside some loop because Apache create a log error file for each iteration and you run out of disk space. Correct your script and delete the log files may solve your problem.
确保您没有忘记某个循环内任何变量之前的 $ 签名,因为 Apache 为每次迭代创建一个日志错误文件,并且您的磁盘空间不足。更正您的脚本并删除日志文件可能会解决您的问题。
回答by robjmills
This sounds like a JavaScript issue to me. A PHP request would not make Firefox unusable whereas an errant JavaScript script could very easily do this.
这对我来说听起来像是 JavaScript 问题。PHP 请求不会使 Firefox 无法使用,而错误的 JavaScript 脚本可以很容易地做到这一点。

