add busyTimeout() to deal with concurrency. open read-write only when needed
This commit is contained in:
@@ -10,6 +10,7 @@ session_set_cookie_params(7200);
|
||||
session_start();
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
@@ -28,57 +29,36 @@ if (file_exists('./scripts/thisrun.txt')) {
|
||||
</div><div class=\"centered\"><h3>$site_name</h3></div><hr>";
|
||||
}
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
$statement1 = $db->prepare('SELECT COUNT(*) FROM detections');
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement1);
|
||||
$result1 = $statement1->execute();
|
||||
$totalcount = $result1->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\', \'localtime\')');
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
$todaycount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == Date(\'now\', \'localtime\') AND TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');
|
||||
if($statement3 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result3 = $statement3->execute();
|
||||
$hourcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Time, Confidence FROM detections LIMIT 1');
|
||||
if($statement4 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement4);
|
||||
$result4 = $statement4->execute();
|
||||
$mostrecent = $result4->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement5 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date == Date(\'now\', \'localtime\')');
|
||||
if($statement5 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement5);
|
||||
$result5 = $statement5->execute();
|
||||
$todayspeciestally = $result5->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections');
|
||||
if($statement6 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement6);
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
@@ -205,10 +185,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
||||
}
|
||||
|
||||
}
|
||||
if($statement0 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement0);
|
||||
$result0 = $statement0->execute();
|
||||
|
||||
?> <table>
|
||||
|
||||
Reference in New Issue
Block a user