本来好好的,昨天突然就没问题,打开一个页面,要20,30秒。。
试着打开静态页面,很快,说明是php或mysql的问题。。
然后跟踪,发现在mysql_connect()这个函数的时候,花了20秒的时间,
把数据库改成本地的,发现查询很快,去连局域网内另一台电脑的数据库,很慢
奇怪了,我网络状没改,php代码没改,mysql也没改,怎么就查询的这么慢了呢?求指点急呀。。会不会跟mysql连接数有关呀??
试着打开静态页面,很快,说明是php或mysql的问题。。
然后跟踪,发现在mysql_connect()这个函数的时候,花了20秒的时间,
把数据库改成本地的,发现查询很快,去连局域网内另一台电脑的数据库,很慢
奇怪了,我网络状没改,php代码没改,mysql也没改,怎么就查询的这么慢了呢?求指点急呀。。会不会跟mysql连接数有关呀??
解决方案 »
- Wepress发布v1.1.1
- ajax 输出是【object object]
- 我安装了xampp,可是apache总是不能运行,这是为什么?
- php+mysql数据库问题
- 客户要做个做个Digg类型的站点,收多少钱合适?
- 文件上传不了的问题,急死人了
- PHP + MySQL 操作DB的问题!在线等。。。。。
- (+50) smarty中的复选框怎样实现多选?
- #Win2000Server + apache2.0.49 +php-4.3.5-Win32.zip ?
- 各位老兄有没有考虑一个程序员以后的发展方向?大家来设计设计!这是每个程序员必须考虑的。
- 我使用的是WIN 2003 的IIS 准备配置PHP环境,但是我无论怎么样配置php.ini,都说我没有开启GD
- 模拟登陆中出现的问题
{
$this->conn_id = @mysql_connect($dbhost, $dbuser, $dbpw, true);
}
else
{
$this->conn_id = @mysql_connect($dbhost, $dbuser, $dbpw); }
if (!$this->conn_id)
{
if (!$quiet)
{
$this->ErrorMsg("Connect Eorror MySQL Server($dbhost)!");
} return false;
} 在这 @mysql_connect($dbhost, $dbuser, $dbpw);
花了20秒的时间
你ping你的服务器(在出现逆所说的问题的时候多ping几次,看看是不是断断续续的)
mysql_pconnect是持久性连接,如果你在程序中不去关闭,这样的话,如果访问数据的量比较多,连接池会满,就会产生资源耗尽,这样网站访问起来就会比较慢甚至访问不了.因为mysql的连接时有限制的.
mysql_connect在使用完毕后,会自动关闭连接,释放连接池.
如果不是频繁的访问数据库,一般的就用mysql_connect。
都会出现数据库连接很慢
会不会跟php的版本有关系呀,,吐血中
我用的是 linux+php5.1.6+nginx
受网速影响是肯定的.
; Allow or prevent persistent links.
mysql.allow_persistent = On; Maximum number of persistent links. -1 means no limit.
mysql.max_persistent = -1; Maximum number of links (persistent + non-persistent). -1 means no limit.
mysql.max_links = -1; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysql.default_port =; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =; Maximum time (in secondes) for connect timeout. -1 means no limit
mysql.connect_timeout = 60; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off[MySQLi]; Maximum number of links. -1 means no limit.
mysqli.max_links = -1; Default port number for mysqli_connect(). If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host =; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user =; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =; Allow or prevent reconnect
mysqli.reconnect = Off[mSQL]
; Allow or prevent persistent links.
msql.allow_persistent = On; Maximum number of persistent links. -1 means no limit.
msql.max_persistent = -1; Maximum number of links (persistent+non persistent). -1 means no limit.
msql.max_links = -1====================================================
php.ini里面的配置都没怎么改
但是这种情况也是查10有5,6次出现,不是每次都这样。
另外,我用jsp代码去查同一个数据,很快的想来想去,真可能是php.ini 设置问题,或者 php的版本问题(现版本 5.1.6)或者nginx有问题。。
不知道如何解决
尝试在mysql服务端的my.cnf配置文件的[mysqld]下加进去skip-name-resolve
然后重启,试试.
show VARIABLES like '%timeout%';还是600,
set global wait_timeout=60;
返回:Query OK, 0 rows affected (0.00 sec)
set wait_timeout=60;
返回:Query OK, 0 rows affected (0.00 sec)重启后再show VARIABLES like '%timeout%';
还是 600,操蛋了
是日志文件吗?可删除否?
不过,感觉还是没解决问题,需要进一步观察
可网站却变慢了系统中有啥时在变的呢,而且变化是影响访问速度的呢。
物理内存??mysql日志??还是有其它??等待高手来解答,帮我找到问题的根本所在
如
10.10.10.30:33603 10.10.10.31:mysql TIME_WAIT
求解呀。。