PHP - DB 연결에 connection pool 적용
This commit is contained in:
1 parent
144caf351f
commit
fb59286dd4
3 files changed
+24
-6
No files matched your search
+2
-1
@@ -17,4 +17,5 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
# mac
|
# mac
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
/doc/obsidian
|
||||||
@@ -20,6 +20,11 @@ RUN { \
|
|||||||
ENV TZ=Asia/Seoul
|
ENV TZ=Asia/Seoul
|
||||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
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' \
|
RUN printf '#!/bin/sh\ncp /var/www/html/mouse_typing/index.html /var/www/html/index.html\nexec "$@"\n' \
|
||||||
> /usr/local/bin/entrypoint.sh \
|
> /usr/local/bin/entrypoint.sh \
|
||||||
&& chmod +x /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;
|
if (!isset($db_port)) $db_port = 3306;
|
||||||
|
|
||||||
|
|
||||||
// connect db
|
// connect db with persistent connection (connection pool)
|
||||||
$db_conn = new mysqli($db_host, $db_user, $db_passwd, $db_name, $db_port);
|
$db_conn = new mysqli("p:".$db_host, $db_user, $db_passwd, $db_name, $db_port);
|
||||||
|
|
||||||
if ($db_conn->connect_error) {
|
if ($db_conn->connect_error) {
|
||||||
set_error_message("DB connection failed.");
|
set_error_message("DB connection failed.");
|
||||||
send_result_fail();
|
send_result_fail();
|
||||||
exit;
|
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