mirror of
https://github.com/vrana/adminer.git
synced 2026-01-10 09:33:06 +01:00
New plugin: Specify query timeout
This commit is contained in:
48
plugins/timeout.php
Normal file
48
plugins/timeout.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/** Specify timeout for running every query
|
||||
* @link https://www.adminer.org/plugins/#use
|
||||
* @author Jakub Vrana, https://www.vrana.cz/
|
||||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||
*/
|
||||
class AdminerTimeout extends Adminer\Plugin {
|
||||
private $seconds;
|
||||
|
||||
/**
|
||||
* @param int $seconds
|
||||
*/
|
||||
function __construct($seconds = 5) {
|
||||
$this->seconds = $seconds;
|
||||
}
|
||||
|
||||
function afterConnect() {
|
||||
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
|
||||
if ($seconds != '') {
|
||||
$ms = $seconds * 1000;
|
||||
$conn = Adminer\connection();
|
||||
switch (Adminer\JUSH) {
|
||||
case 'sql': $conn->query("SET max_execution_time = $ms"); break;
|
||||
case 'pgsql': $conn->query("SET statement_timeout = $ms"); break;
|
||||
case 'mssql': $conn->query("SET LOCK_TIMEOUT $ms"); break;
|
||||
default:
|
||||
if (method_exists(connection(), 'timeout')) {
|
||||
$conn->timeout($ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function config() {
|
||||
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
|
||||
return array($this->lang('Queries timeout') => '<input type="number" name="config[timeout]" min="0" value="' . Adminer\h($seconds) . '" class="size"> ' . $this->lang('seconds'));
|
||||
}
|
||||
|
||||
protected $translations = array(
|
||||
'cs' => array(
|
||||
'' => 'Nastaví timeout pro spouštění každého dotazu',
|
||||
'Queries timeout' => 'Timeout dotazů',
|
||||
'seconds' => 'sekund',
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user