簡體   English   中英

Azure 應用服務:未捕獲的 PDOException:SQLSTATE[HY000]:一般錯誤:5 數據庫已鎖定

[英]Azure App Service: Uncaught PDOException: SQLSTATE[HY000]: General error: 5 database is locked

從 Azure 應用服務執行以下代碼時,我收到以下錯誤:

可在以下詳細信息下找到用於旋轉此 Azure 應用服務的容器:

服務器: https ://mcr.microsoft.com 圖片:appsvc/wordpress-alpine-php:latest

function createStructure( $info )
{
  $contentFolder = __DIR__ . DIRECTORY_SEPARATOR . '.content.' . getRandomString( 8 );
  $newDbFile     = $contentFolder . DIRECTORY_SEPARATOR . 'structure.db';
  mkdir( $contentFolder, 0777, true );
  mkdir( $contentFolder . DIRECTORY_SEPARATOR . 'html', 0777, true );
  mkdir( $contentFolder . DIRECTORY_SEPARATOR . 'binary', 0777, true );
  mkdir( $contentFolder . DIRECTORY_SEPARATOR . 'backup', 0777, true );
  mkdir( $contentFolder . DIRECTORY_SEPARATOR . 'imports', 0777, true );
  touch( $contentFolder . DIRECTORY_SEPARATOR . 'empty.css' );
  touch( $contentFolder . DIRECTORY_SEPARATOR . 'empty.js' );
  touch( $contentFolder . DIRECTORY_SEPARATOR . 'empty.js' );
  file_put_contents( $contentFolder . DIRECTORY_SEPARATOR . '1px.png', base64_decode( 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAAnRSTlMAAHaTzTgAAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC' ) );
  file_put_contents( $contentFolder . DIRECTORY_SEPARATOR . 'empty.ico', base64_decode( 'AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAQAAAAAAAAAAAAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA' ) );
  $newDb = new PDO( "sqlite:{$newDbFile}" );
  $newDb->exec( "PRAGMA journal_mode=WAL" );
  createTable( 'structure', $newDb );
  createTable( 'settings', $newDb );
  foreach ( $info['info']['settings'] as $param => $value ) {
    $stmt = $newDb->prepare( "INSERT INTO settings VALUES(:param, :value)" );
    $stmt->execute( ['param' => $param, 'value' => $value] );
  }
  return $contentFolder;
}

錯誤信息:

Starting Live Log Stream ---
2022-04-17T09:22:08.084875633Z: [INFO]  PHP 8.0.11 (cli) (built: Oct 14 2021 22:56:25) ( NTS )
2022-04-17T09:22:08.084935033Z: [INFO]  Copyright (c) The PHP Group
2022-04-17T09:22:08.084943433Z: [INFO]  Zend Engine v4.0.11, Copyright (c) Zend Technologies
2022-04-17T09:22:08.084949533Z: [INFO]      with Zend OPcache v8.0.11, Copyright (c), by Zend Technologies
2022-04-17T09:22:08.097821418Z: [INFO]  Setup openrc ...
2022-04-17T09:22:08.422734722Z: [ERROR]  Service "hwdrivers' needs non existent service "dev"
2022-04-17T09:22:08.423166221Z: [ERROR]  Service "machine-id' needs non existent service "dev"
2022-04-17T09:22:08.423805420Z: [INFO]   * Caching service dependencies ... [ ok ]
2022-04-17T09:22:08.442953497Z: [INFO]  INFO: Log folder for nginx/php not found. creating...
2022-04-17T09:22:08.458433778Z: [INFO]  INFO: Found an existing WordPress status file ...
2022-04-17T09:22:08.569514843Z: [INFO]  INFO: Check SSL Setting...
2022-04-17T09:22:08.574120737Z: [INFO]  INFO: SSL Settings exist!
2022-04-17T09:22:08.578651232Z: [INFO]  REDIS_MAX_MEMORY_MB must be an integer..
2022-04-17T09:22:08.583817925Z: [INFO]  Starting Redis with Max Memory: 815301KB
2022-04-17T09:22:08.583851525Z: [INFO]  INFO: /var/log/supervisor not found. creating ...
2022-04-17T09:22:08.585432723Z: [INFO]  INFO: Updating PHP configurations...
2022-04-17T09:22:08.587717321Z: [INFO]  INFO: creating /run/php/php-fpm.sock ...
2022-04-17T09:22:08.588212220Z: [INFO]  134:C 17 Apr 2022 09:22:08.587 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2022-04-17T09:22:08.588236720Z: [INFO]  134:C 17 Apr 2022 09:22:08.587 # Redis version=6.0.16, bits=64, commit=2858e290, modified=0, pid=134, just started
2022-04-17T09:22:08.588245020Z: [INFO]  134:C 17 Apr 2022 09:22:08.587 # Configuration loaded
2022-04-17T09:22:08.595743311Z: [INFO]  134:M 17 Apr 2022 09:22:08.595 * Running mode=standalone, port=6379.
2022-04-17T09:22:08.596938609Z: [INFO]  134:M 17 Apr 2022 09:22:08.595 # Server initialized
2022-04-17T09:22:08.602717002Z: [INFO]  134:M 17 Apr 2022 09:22:08.602 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2022-04-17T09:22:08.602774902Z: [INFO]  134:M 17 Apr 2022 09:22:08.602 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never').
2022-04-17T09:22:08.602889702Z: [INFO]  134:M 17 Apr 2022 09:22:08.602 * Ready to accept connections
2022-04-17T09:22:08.607710496Z: [INFO]  Starting SSH ...
2022-04-17T09:22:08.608545495Z: [INFO]  Starting php-fpm ...
2022-04-17T09:22:08.608568495Z: [INFO]  Starting Nginx ...
2022-04-17T09:22:11.059816295Z: [INFO]  2022-04-17 09:22:11,059 INFO Set uid to user 0 succeeded
2022-04-17T09:22:11.071782891Z: [INFO]  2022-04-17 09:22:11,071 INFO supervisord started with pid 145
2022-04-17T09:22:12.078339674Z: [INFO]  2022-04-17 09:22:12,077 INFO spawned: 'php-fpm' with pid 147
2022-04-17T09:22:12.087204670Z: [INFO]  2022-04-17 09:22:12,086 INFO spawned: 'delay' with pid 148
2022-04-17T09:22:12.095654167Z: [INFO]  2022-04-17 09:22:12,089 INFO spawned: 'nginx' with pid 149
2022-04-17T09:22:12.098493065Z: [INFO]  2022-04-17 09:22:12,098 INFO spawned: 'sshd' with pid 150
2022-04-17T09:22:12.107153962Z: [INFO]  2022-04-17 09:22:12,106 INFO spawned: 'watch-log-files' with pid 152
2022-04-17T09:22:14.016132270Z: [INFO]  2022-04-17 09:22:14,015 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-04-17T09:22:14.016186470Z: [INFO]  2022-04-17 09:22:14,016 INFO success: delay entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-04-17T09:22:14.016538270Z: [INFO]  2022-04-17 09:22:14,016 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-04-17T09:22:14.016786670Z: [INFO]  2022-04-17 09:22:14,016 INFO success: sshd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-04-17T09:22:14.016891269Z: [INFO]  2022-04-17 09:22:14,016 INFO success: watch-log-files entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2022-04-17T09:22:15.610369307Z: [INFO]  2022-04-17 09:22:15,609 INFO exited: sshd (exit status 0; expected)
2022-04-17T09:22:17.112204781Z: [INFO]  2022-04-17 09:22:17,111 INFO exited: delay (exit status 0; expected)
2022-04-17T09:23:38  No new trace in the past 1 min(s).
2022-04-17T09:24:03.643278984Z: [ERROR]  2022/04/17 09:24:03 [error] 165#165: *10 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000]: General error: 5 database is locked in /home/site/wwwroot/load/load.php:1121
2022-04-17T09:24:03.643317984Z: [ERROR]  Stack trace:
2022-04-17T09:24:03.643326084Z: [ERROR]  #0 /home/site/wwwroot/load/load.php(1121): PDO->exec('PRAGMA journal_...')
2022-04-17T09:24:03.643332684Z: [ERROR]  #1 /home/site/wwwroot/load/load.php(6571): createStructure(Array)
2022-04-17T09:24:03.643338184Z: [ERROR]  #2 {main}
2022-04-17T09:24:03.643343684Z: [ERROR]    thrown in /home/site/wwwroot/load/load.php on line 1121" while reading response header from upstream, client: 169.254.142.1, server: _, request: "POST /load/load.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php-fpm.sock:", host: "--------.azurewebsites.net"

大概是這樣的:

底層存儲是 NFS/CIFS,這就是為什么不建議 SQLite 安裝存儲。 最好的解決方法是利用 PostgreSQL 或 MySQL。

參考

現有的問答存在,對您來說可能不是新聞。


在腳本級別:

解決方案是捕獲異常並處理它。 例如,使腳本在數據庫不可用的錯誤條件下工作。

然后使其可配置,嘗試可能會或可能不會解決您的問題的不同配置,最后可以選擇使用旨在工作的數據庫存儲服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM