Copyright 1997-2010 the PHP Documentation Group.
The behaviour of these functions is affected by settings in php.ini
.
Table 22.19. MySQL Native Driver Configuration Options
Name | Default | Changeable | Changelog |
---|---|---|---|
mysqlnd.collect_statistics | "1" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
mysqlnd.collect_memory_statistics | "0" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
mysqlnd.debug | "0" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
mysqlnd.net_read_timeout | "31536000" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
mysqlnd.net_cmd_buffer_size | 5.3.0 - "2048", 5.3.1 - "4096" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
mysqlnd.net_read_buffer_size | "32768" | PHP_INI_SYSTEM | Available since PHP 5.3.0. |
For further details and definitions of the PHP_INI_* modes, see the configuration.changes.modes.
Here's a short explanation of the configuration directives.
-
mysqlnd.collect_statistics
boolean Enables the collection of various client statistics which can be accessed through
mysqli_get_client_stats
,mysqli_get_connection_stats
,mysqli_get_cache_stats
and are shown inmysqlnd
section of the output of thephpinfo
function as well.This configuration setting enables all MySQL Native Driver statistics except those relating to memory management.
-
mysqlnd.collect_memory_statistics
boolean Enable the collection of various memory statistics which can be accessed through
mysqli_get_client_stats
,mysqli_get_connection_stats
,mysqli_get_cache_stats
and are shown inmysqlnd
section of the output of thephpinfo
function as well.This configuration setting enables the memory management statistics within the overall set of MySQL Native Driver statistics.
-
mysqlnd.debug
string Records communication from all extensions using
mysqlnd
to the specified log file.The format of the directive is
mysqlnd.debug = "option1[,parameter_option1][:option2[,parameter_option2]]"
.The options for the format string are as follows:
A[,file] - Appends trace output to specified file. Also ensures that data is written after each write. This is done by closing and reopening the trace file (this is slow). It helps ensure a complete log file should the application crash.
a[,file] - Appends trace output to the specified file.
d - Enables output from DBUG_<N> macros for the current state. May be followed by a list of keywords which selects output only for the DBUG macros with that keyword. An empty list of keywords implies output for all macros.
f[,functions] - Limits debugger actions to the specified list of functions. An empty list of functions implies that all functions are selected.
F - Marks each debugger output line with the name of the source file containing the macro causing the output.
i - Marks each debugger output line with the PID of the current process.
L - Marks each debugger output line with the name of the source file line number of the macro causing the output.
n - Marks each debugger output line with the current function nesting depth
o[,file] - Similar to a[,file] but overwrites old file, and does not append.
O[,file] - Similar to A[,file] but overwrites old file, and does not append.
t[,N] - Enables function control flow tracing. The maximum nesting depth is specified by N, and defaults to 200.
x - This option activates profiling.
Example:
d:t:x:O,/tmp/mysqlnd.trace
NoteThis feature is only available with a debug build of PHP. Works on Microsoft Windows if using a debug build of PHP and PHP was built using Microsoft Visual C version 9 and above.
-
mysqlnd.net_read_timeout
integer mysqlnd
and the MySQL Client Library,libmysql
use different networking APIs.mysqlnd
uses PHP streams, whereaslibmysql
uses its own wrapper around the operating level network calls. PHP, by default, sets a read timeout of 60s for streams. This is set viaphp.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 afterdefault_socket_timeout
seconds resulting in an error message “2006 - MySQL Server has gone away”. The MySQL Client Library sets a default timeout of 365 * 24 * 3600 seconds (1 year) and waits for other timeouts to occur, such as TCP/IP timeouts.mysqlnd
now uses the same very long timeout. The value is configurable through a newphp.ini
setting:mysqlnd.net_read_timeout
.mysqlnd.net_read_timeout
gets used by any extension (ext/mysql
,ext/mysqli
,PDO_MySQL
) that usesmysqlnd
.mysqlnd
tells PHP Streams to usemysqlnd.net_read_timeout
. Please note that there may be subtle differences betweenMYSQL_OPT_READ_TIMEOUT
from the MySQL Client Library and PHP Streams, for exampleMYSQL_OPT_READ_TIMEOUT
is documented to work only for TCP/IP connections and, prior to MySQL 5.1.2, only for Windows. PHP streams may not have this limitation. Please check the streams documentation, if in doubt.-
mysqlnd.net_cmd_buffer_size
long mysqlnd
allocates an internal command/network buffer ofmysqlnd.net_cmd_buffer_size
(inphp.ini
) bytes for every connection. If a MySQL Client Server protocol command, for example,COM_QUERY
(“normal” query), does not fit into the buffer,mysqlnd
will grow the buffer to the size required for sending the command. Whenever the buffer gets extended for one connection,command_buffer_too_small
will be incremented by one.If
mysqlnd
has to grow the buffer beyond its initial size ofmysqlnd.net_cmd_buffer_size
bytes for almost every connection, you should consider increasing the default size to avoid re-allocations.The default buffer size is 2048 bytes in PHP 5.3.0. In later versions the default is 4096 bytes. The default can changed either through the
php.ini
settingmysqlnd.net_cmd_buffer_size
or usingmysqli_options(MYSQLI_OPT_NET_CMD_BUFFER_SIZE, int size)
.It is recommended that the buffer size be set to no less than 4096 bytes because
mysqlnd
also uses it when reading certain communication packet from MySQL. In PHP 5.3.0,mysqlnd
will not grow the buffer if MySQL sends a packet that is larger than the current size of the buffer. As a consequence,mysqlnd
is unable to decode the packet and the client application will get an error. There are only two situations when the packet can be larger than the 2048 bytes default ofmysqlnd.net_cmd_buffer_size
in PHP 5.3.0: the packet transports a very long error message, or the packet holds column meta data fromCOM_LIST_FIELD
(mysql_list_fields()
and the meta data come from a string column with a very long default value (>1900 bytes).As of PHP 5.3.2 mysqlnd does not allow setting buffers smaller than 4096 bytes.
The value can also be set using
mysqli_option(link, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, size)
.-
mysqlnd.net_read_buffer_size
long Maximum read chunk size in bytes when reading the body of a MySQL command packet. The MySQL client server protocol encapsulates all its commands in packets. The packets consist of a small header and a body with the actual payload. The size of the body is encoded in the header.
mysqlnd
reads the body in chunks ofMIN(header.size, mysqlnd.net_read_buffer_size)
bytes. If a packet body is larger thanmysqlnd.net_read_buffer_size
bytes,mysqlnd
has to callread()
multiple times.The value can also be set using
mysqli_optionS(link, MYSQLI_OPT_NET_READ_BUFFER_SIZE, size)
.