PHP - DB 연결에 connection pool 적용
This commit is contained in:
1 parent
144caf351f
commit
fb59286dd4
3 files changed
+23
-5
No files matched your search
@@ -18,3 +18,4 @@ __pycache__/
|
||||
|
||||
# mac
|
||||
.DS_Store
|
||||
/doc/obsidian
|
||||
@@ -20,6 +20,11 @@ RUN { \
|
||||
ENV TZ=Asia/Seoul
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
RUN { \
|
||||
echo 'mysqli.max_persistent = 1'; \
|
||||
echo 'mysqli.max_links = -1'; \
|
||||
} > /usr/local/etc/php/conf.d/mysqli-pool.ini
|
||||
|
||||
RUN printf '#!/bin/sh\ncp /var/www/html/mouse_typing/index.html /var/www/html/index.html\nexec "$@"\n' \
|
||||
> /usr/local/bin/entrypoint.sh \
|
||||
&& chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
@@ -13,15 +13,27 @@ if($hasServiceDBSetting == true) {
|
||||
if (!isset($db_port)) $db_port = 3306;
|
||||
|
||||
|
||||
// connect db
|
||||
$db_conn = new mysqli($db_host, $db_user, $db_passwd, $db_name, $db_port);
|
||||
// connect db with persistent connection (connection pool)
|
||||
$db_conn = new mysqli("p:".$db_host, $db_user, $db_passwd, $db_name, $db_port);
|
||||
|
||||
if ($db_conn->connect_error) {
|
||||
set_error_message("DB connection failed.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
} else {
|
||||
$query = "USE chocomae";
|
||||
$result = mysqli_query($db_conn, $query);
|
||||
}
|
||||
|
||||
// verify connection is alive (handle wait_timeout from server)
|
||||
if (!$db_conn->ping()) {
|
||||
$db_conn->close();
|
||||
$db_conn = new mysqli("p:".$db_host, $db_user, $db_passwd, $db_name, $db_port);
|
||||
if ($db_conn->connect_error) {
|
||||
set_error_message("DB connection failed.");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$query = "USE chocomae";
|
||||
$result = mysqli_query($db_conn, $query);
|
||||
|
||||
?>
|
||||
Reference in new issue
Block a user