简体   繁体   English

PHP与MySQL结合使用非常慢

[英]PHP in combination with MySQL is extremely slow

I am currently experiencing slowness with one of my servers. 我的一台服务器目前运行缓慢。 It is running an apache2 server with PHP and MySQL. 它正在使用PHP和MySQL运行apache2服务器。 The MySQL server is hosted on the same machine as the webserver itself. MySQL服务器与Web服务器本身托管在同一台计算机上。

Whenever I request a PHP file containing MySQL queries the page needs approximately 24 seconds to show up. 每当我请求包含MySQL查询的PHP文件时,该页面大约需要24秒才能显示出来。 While requesting the page the CPU usage of apache2 goes up to 11% (!) which is very much in comparison to what it used to be a week ago. 请求页面时,apache2的CPU使用率上升了11%(!),与一周前相比,这是非常多的。

Non-PHP files or PHP files without MySQL queries are showing up immediately. 非PHP文件或没有MySQL查询的PHP文件会立即显示。

What could be causing the problems with scripts containing MySQL queries? 是什么原因导致包含MySQL查询的脚本出现问题? I was unable to find any useful information inside the apache error logs. 我无法在apache错误日志中找到任何有用的信息。

database queries take time to run, and each query involves opening up at least one file. 数据库查询需要花一些时间才能运行,并且每个查询都涉及打开至少一个文件。 file access is slow. 文件访问速度慢。

you can speed up the requests by running the database in RAM instead of from the hard-drive, but the real answer is probably to cache as much as you can so you're doing as little database querying as possible. 您可以通过在RAM中而不是从硬盘驱动器中运行数据库来加快请求的速度,但是真正的答案可能是尽可能多地缓存,因此您在进行尽可能少的数据库查询。

In mysql console 在mysql控制台中

show full processlist;  <-- to show what are the current SQL

To check where is the log file:- 要检查日志文件在哪里:

show variables like '%log%'; <-- to show mysql variables

When doing query benchmark / testing, always remember to turn off query cache, using :- 在执行查询基准测试/测试时,请始终记住使用以下命令关闭查询缓存:

set session query_cache_type=off;

由于某些cms日志记录功能,您可以检查mysql数据库是否大于2GB(或4GB),并且超出文件大小限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM