Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

PHP里mysqlnd.net_read_timeout和default_socket_timeout的区别?

在PHP里,如果想限制一个SQL语句的最长执行时间,可以通过配置php.ini里的mysqlnd.net_read_timeout的值来实现,经测试,配置mysqlnd.net_read_timeout = 10后,执行一个时间超过10秒的语句,PHP确实会超时报错。但如果配置的是default_socket_timeout = 10,PHP并不会报错,看起来mysql的读写超时并不受default_socket_timeout参数控制。

但是PHP文档里(链接)的描述是:

PHP, by default, sets a read timeout of 60s for streams. This is set via php.ini, default_socket_timeout. This default applies to all streams that set no other timeout value. mysqlnd does not set any other value and therefore connections of long running queries can be disconnected after default_socket_timeout seconds resulting in an error message 2006 - MySQL Server has gone away.

描述里说SQL语句执行时间超过default_socket_timeout的话,PHP会报错,文档描述跟实际测试情况不一样,令我比较迷惑。

问题:
1)mysql会不会受default_socket_timeout的影响?
2)mysqlnd.net_read_timeoutdefault_socket_timeout这2个配置项有什么关系和区别?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...