Skip to content

Commit 4444abd

Browse files
committed
- add support of mysqlnd driver (instead of using libmysqlclient)
- move query text in header (defined only once)
1 parent 846ff27 commit 4444abd

6 files changed

Lines changed: 347 additions & 53 deletions

File tree

apm.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#ifdef APM_DRIVER_SQLITE3
4545
# include "driver_sqlite3.h"
4646
#endif
47-
#ifdef APM_DRIVER_MYSQL
47+
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
4848
# include "driver_mysql.h"
4949
#endif
5050
#ifdef APM_DRIVER_STATSD
@@ -186,7 +186,7 @@ PHP_INI_BEGIN()
186186
STD_PHP_INI_BOOLEAN("apm.sqlite_process_silenced_events", "1", PHP_INI_PERDIR, OnUpdateBool, sqlite3_process_silenced_events, zend_apm_globals, apm_globals)
187187
#endif
188188

189-
#ifdef APM_DRIVER_MYSQL
189+
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
190190
/* Boolean controlling whether the driver is active or not */
191191
STD_PHP_INI_BOOLEAN("apm.mysql_enabled", "1", PHP_INI_PERDIR, OnUpdateBool, mysql_enabled, zend_apm_globals, apm_globals)
192192
/* Boolean controlling the collection of stats */
@@ -260,7 +260,7 @@ static PHP_GINIT_FUNCTION(apm)
260260
*next = apm_driver_sqlite3_create();
261261
next = &(*next)->next;
262262
#endif
263-
#ifdef APM_DRIVER_MYSQL
263+
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
264264
*next = apm_driver_mysql_create();
265265
next = &(*next)->next;
266266
#endif
@@ -457,6 +457,21 @@ PHP_MINFO_FUNCTION(apm)
457457
php_info_print_table_start();
458458
php_info_print_table_row(2, "APM support", "enabled");
459459
php_info_print_table_row(2, "Version", PHP_APM_VERSION);
460+
#ifdef APM_DRIVER_SQLITE3
461+
php_info_print_table_row(2, "Sqlite3 driver", "enabled");
462+
#endif
463+
#ifdef APM_DRIVER_MYSQL
464+
php_info_print_table_row(2, "MySQL driver (mysqlnd)", "enabled");
465+
#endif
466+
#ifdef APM_DRIVER_MYSQLND
467+
php_info_print_table_row(2, "MySQL driver (libmysqlclient)", "enabled");
468+
#endif
469+
#ifdef APM_DRIVER_STATSD
470+
php_info_print_table_row(2, "Statsd driver", "enabled");
471+
#endif
472+
#ifdef APM_DRIVER_SOCKET
473+
php_info_print_table_row(2, "Socket driver", "enabled");
474+
#endif
460475
php_info_print_table_end();
461476

462477
DISPLAY_INI_ENTRIES();

config.m4

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ PHP_ARG_ENABLE(apm, whether to enable apm support,
2929
[ --enable-apm Enable apm support], yes)
3030
PHP_ARG_WITH(sqlite3, enable support for sqlite3,
3131
[ --with-sqlite3=DIR Location of sqlite3 library], yes, no)
32-
PHP_ARG_WITH(mysql, enable support for MySQL,
32+
PHP_ARG_WITH(mysqlnd, enable support for MySQL through mysqlnd,
33+
[ --with-mysqlnd Enable mysqlnd support], no, no)
34+
PHP_ARG_WITH(mysql, enable support for MySQL through libmysqlclient,
3335
[ --with-mysql=DIR Location of MySQL base directory], yes, no)
3436
PHP_ARG_ENABLE(statsd, enable support for statsd,
3537
[ --enable-statsd Enable statsd support], yes, no)
@@ -103,7 +105,18 @@ if test "$PHP_APM" != "no"; then
103105
fi
104106
fi
105107

106-
if test "$PHP_MYSQL" != "no"; then
108+
if test "$PHP_MYSQLND" != "no"; then
109+
mysql_driver="driver_mysqlnd.c"
110+
AC_MSG_CHECKING([mysqlnd headers])
111+
if test -f $phpincludedir/ext/mysqlnd/mysqlnd.h; then
112+
AC_MSG_RESULT(found)
113+
AC_DEFINE(APM_DRIVER_MYSQLND, 1, [activate MySQL storage driver])
114+
else
115+
AC_MSG_RESULT(not found)
116+
AC_MSG_ERROR([Please check PHP is build with mysqlnd])
117+
fi
118+
119+
elif test "$PHP_MYSQL" != "no"; then
107120
mysql_driver="driver_mysql.c"
108121
AC_DEFINE(APM_DRIVER_MYSQL, 1, [activate MySQL storage driver])
109122

driver_mysql.c

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,52 +61,9 @@ MYSQL * mysql_get_instance(TSRMLS_D) {
6161

6262
mysql_set_character_set(APM_G(mysql_event_db), "utf8");
6363

64-
mysql_query(
65-
APM_G(mysql_event_db),
66-
"\
67-
CREATE TABLE IF NOT EXISTS request (\
68-
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
69-
application VARCHAR(255) NOT NULL,\
70-
ts TIMESTAMP NOT NULL,\
71-
script TEXT NOT NULL,\
72-
uri TEXT NOT NULL,\
73-
host TEXT NOT NULL,\
74-
ip INTEGER UNSIGNED NOT NULL,\
75-
cookies TEXT NOT NULL,\
76-
post_vars TEXT NOT NULL,\
77-
referer TEXT NOT NULL,\
78-
method TEXT NOT NULL\
79-
)"
80-
);
81-
mysql_query(
82-
APM_G(mysql_event_db),
83-
"\
84-
CREATE TABLE IF NOT EXISTS event (\
85-
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
86-
request_id INTEGER UNSIGNED,\
87-
ts TIMESTAMP NOT NULL,\
88-
type SMALLINT UNSIGNED NOT NULL,\
89-
file TEXT NOT NULL,\
90-
line MEDIUMINT UNSIGNED NOT NULL,\
91-
message TEXT NOT NULL,\
92-
backtrace BLOB NOT NULL,\
93-
KEY request (request_id)\
94-
)"
95-
);
96-
97-
mysql_query(
98-
APM_G(mysql_event_db),
99-
"\
100-
CREATE TABLE IF NOT EXISTS stats (\
101-
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
102-
request_id INTEGER UNSIGNED,\
103-
duration FLOAT UNSIGNED NOT NULL,\
104-
user_cpu FLOAT UNSIGNED NOT NULL,\
105-
sys_cpu FLOAT UNSIGNED NOT NULL,\
106-
mem_peak_usage INTEGER UNSIGNED NOT NULL,\
107-
KEY request (request_id)\
108-
)"
109-
);
64+
mysql_query(APM_G(mysql_event_db), TABLE_REQUEST);
65+
mysql_query(APM_G(mysql_event_db), TABLE_EVENT);
66+
mysql_query(APM_G(mysql_event_db), TABLE_STATS);
11067
}
11168

11269
return APM_G(mysql_event_db);
@@ -185,7 +142,7 @@ static void apm_driver_mysql_insert_request(TSRMLS_D)
185142
if (mysql_query(connection, sql) != 0)
186143
APM_DEBUG("[MySQL driver] Error: %s\n", mysql_error(APM_G(mysql_event_db)));
187144

188-
mysql_query(connection, "SET @request_id = LAST_INSERT_ID()");
145+
mysql_query(connection, QUERY_REQUEST_ID);
189146

190147
efree(sql);
191148
if (application_esc)

driver_mysql.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,45 @@ apm_driver_entry * apm_driver_mysql_create();
3636

3737
PHP_INI_MH(OnUpdateAPMmysqlErrorReporting);
3838

39+
#define TABLE_REQUEST "\
40+
CREATE TABLE IF NOT EXISTS request (\
41+
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
42+
application VARCHAR(255) NOT NULL,\
43+
ts TIMESTAMP NOT NULL,\
44+
script TEXT NOT NULL,\
45+
uri TEXT NOT NULL,\
46+
host TEXT NOT NULL,\
47+
ip INTEGER UNSIGNED NOT NULL,\
48+
cookies TEXT NOT NULL,\
49+
post_vars TEXT NOT NULL,\
50+
referer TEXT NOT NULL,\
51+
method TEXT NOT NULL\
52+
)"
53+
54+
#define TABLE_EVENT "\
55+
CREATE TABLE IF NOT EXISTS event (\
56+
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
57+
request_id INTEGER UNSIGNED,\
58+
ts TIMESTAMP NOT NULL,\
59+
type SMALLINT UNSIGNED NOT NULL,\
60+
file TEXT NOT NULL,\
61+
line MEDIUMINT UNSIGNED NOT NULL,\
62+
message TEXT NOT NULL,\
63+
backtrace BLOB NOT NULL,\
64+
KEY request (request_id)\
65+
)"
66+
67+
#define TABLE_STATS "\
68+
CREATE TABLE IF NOT EXISTS stats (\
69+
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
70+
request_id INTEGER UNSIGNED,\
71+
duration FLOAT UNSIGNED NOT NULL,\
72+
user_cpu FLOAT UNSIGNED NOT NULL,\
73+
sys_cpu FLOAT UNSIGNED NOT NULL,\
74+
mem_peak_usage INTEGER UNSIGNED NOT NULL,\
75+
KEY request (request_id)\
76+
)"
77+
78+
#define QUERY_REQUEST_ID "SET @request_id = LAST_INSERT_ID()"
79+
3980
#endif

0 commit comments

Comments
 (0)