From 62f53234e7487d436dfae9faec021953632eb53c Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Tue, 7 Jul 2026 14:26:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=A1=B5opcache=E5=A4=B1=E6=95=88=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E6=96=B0=E7=89=88=E7=94=9F=E6=95=88=20+=20=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=9F=A5=E8=AF=A2=E6=94=BE=E5=AE=BDbusy=5Ftimeout?= =?UTF-8?q?=E8=87=B315s=E5=B9=B6=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95(?= =?UTF-8?q?=E8=A7=84=E9=81=BFdatabase=20is=20locked)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/cashier.php | 9 ++++++--- orders.php | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/cashier.php b/api/cashier.php index e6d98df..299de8c 100644 --- a/api/cashier.php +++ b/api/cashier.php @@ -160,6 +160,9 @@ function cashierOrderList() { if (session_status() === PHP_SESSION_ACTIVE) session_write_close(); $db = getDB(); + // ★ 订单是纯读查询:显式放宽 busy_timeout 让 SQLite 自身等待锁释放(WAL 下读不阻塞写), + // 大幅降低因 Java 高频写入导致的 "database is locked" 返回概率 + $db->exec('PRAGMA busy_timeout=15000'); $limit = (int)getParam('limit', 100); if ($limit <= 0 || $limit > 500) $limit = 100; $sql = "SELECT * FROM cashier_orders"; @@ -170,10 +173,10 @@ function cashierOrderList() { } $sql .= " ORDER BY created_at DESC LIMIT " . (int)$limit; - // ★ 重试规避 database is locked(Java 高频写入时 SQLite 偶发锁,最多重试4次) + // ★ 重试规避 database is locked(Java 高频写入时 SQLite 偶发锁,最多重试5次,指数退避) $rows = []; $attempts = 0; - while ($attempts < 4) { + while ($attempts < 5) { $attempts++; $stmt = $db->prepare($sql); if (!$stmt) break; @@ -183,7 +186,7 @@ function cashierOrderList() { $result = @$stmt->execute(); if ($result === false) { $err = $db->lastErrorMsg(); - if (stripos($err, 'locked') !== false && $attempts < 4) { usleep(200000); continue; } + if (stripos($err, 'locked') !== false && $attempts < 5) { usleep(200000 * $attempts); continue; } exit(json_encode(['success' => false, 'message' => '查询失败: ' . $err], JSON_UNESCAPED_UNICODE)); } while ($r = $result->fetchArray(SQLITE3_ASSOC)) { diff --git a/orders.php b/orders.php index 6da9b63..d94c467 100644 --- a/orders.php +++ b/orders.php @@ -5,6 +5,10 @@ */ require_once __DIR__ . '/core.php'; +// ★ 强制使 opcache 失效,确保部署后的新版(含请求超时/重试)立即生效, +// 避免 Web 服务端 opcache 持续服务旧版 orders.php(无超时→永久"加载中") +if (function_exists('opcache_invalidate')) { @opcache_invalidate(__FILE__); } + if (session_status() === PHP_SESSION_NONE) session_start(); $loggedIn = isAdminLoggedIn() || isCashierLoggedIn();