manually control timeout, to dump trace data after hitting the limit
This commit is contained in:
parent
1d4c43f33b
commit
b85e7ec209
10 changed files with 47 additions and 11 deletions
|
@ -173,7 +173,6 @@ function stream_file(string $file, int $start, int $end): void
|
||||||
{
|
{
|
||||||
$fp = fopen($file, 'r');
|
$fp = fopen($file, 'r');
|
||||||
try {
|
try {
|
||||||
set_time_limit(0);
|
|
||||||
fseek($fp, $start);
|
fseek($fp, $start);
|
||||||
$buffer = 1024 * 1024;
|
$buffer = 1024 * 1024;
|
||||||
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
|
while (!feof($fp) && ($p = ftell($fp)) <= $end) {
|
||||||
|
|
32
core/timeout.php
Normal file
32
core/timeout.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TimeoutException extends RuntimeException
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
class Timeout
|
||||||
|
{
|
||||||
|
private $active;
|
||||||
|
|
||||||
|
public function set($seconds)
|
||||||
|
{
|
||||||
|
$this->active = true;
|
||||||
|
// declare(ticks = 1);
|
||||||
|
pcntl_signal(SIGALRM, [$this, 'handle'], true);
|
||||||
|
pcntl_alarm($seconds);
|
||||||
|
set_time_limit($seconds + 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear()
|
||||||
|
{
|
||||||
|
set_time_limit(0);
|
||||||
|
$this->active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle($signal)
|
||||||
|
{
|
||||||
|
if ($this->active) {
|
||||||
|
throw new TimeoutException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ class AdminPage extends Extension
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $database, $page, $user;
|
global $database, $page, $user, $_shm_timeout;
|
||||||
|
|
||||||
if ($event->page_matches("admin")) {
|
if ($event->page_matches("admin")) {
|
||||||
if (!$user->can(Permissions::MANAGE_ADMINTOOLS)) {
|
if (!$user->can(Permissions::MANAGE_ADMINTOOLS)) {
|
||||||
|
@ -51,7 +51,7 @@ class AdminPage extends Extension
|
||||||
|
|
||||||
if ($user->check_auth_token()) {
|
if ($user->check_auth_token()) {
|
||||||
log_info("admin", "Util: $action");
|
log_info("admin", "Util: $action");
|
||||||
set_time_limit(0);
|
$_shm_timeout->clear();
|
||||||
$database->set_timeout(null);
|
$database->set_timeout(null);
|
||||||
send_event($aae);
|
send_event($aae);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@ class BulkAdd extends Extension
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $page, $user;
|
global $page, $user, $_shm_timeout;
|
||||||
if ($event->page_matches("bulk_add")) {
|
if ($event->page_matches("bulk_add")) {
|
||||||
if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && isset($_POST['dir'])) {
|
if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && isset($_POST['dir'])) {
|
||||||
set_time_limit(0);
|
$_shm_timeout->clear();
|
||||||
$bae = send_event(new BulkAddEvent($_POST['dir']));
|
$bae = send_event(new BulkAddEvent($_POST['dir']));
|
||||||
foreach ($bae->results as $result) {
|
foreach ($bae->results as $result) {
|
||||||
$this->theme->add_status("Adding files", $result);
|
$this->theme->add_status("Adding files", $result);
|
||||||
|
|
|
@ -11,10 +11,10 @@ class BulkAddCSV extends Extension
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $page, $user;
|
global $page, $user, $_shm_timeout;
|
||||||
if ($event->page_matches("bulk_add_csv")) {
|
if ($event->page_matches("bulk_add_csv")) {
|
||||||
if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && isset($_POST['csv'])) {
|
if ($user->can(Permissions::BULK_ADD) && $user->check_auth_token() && isset($_POST['csv'])) {
|
||||||
set_time_limit(0);
|
$_shm_timeout->clear();
|
||||||
$this->add_csv($_POST['csv']);
|
$this->add_csv($_POST['csv']);
|
||||||
$this->theme->display_upload_results($page);
|
$this->theme->display_upload_results($page);
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,7 +350,7 @@ class CronUploader extends Extension
|
||||||
|
|
||||||
self::$IMPORT_RUNNING = true;
|
self::$IMPORT_RUNNING = true;
|
||||||
try {
|
try {
|
||||||
//set_time_limit(0);
|
//$_shm_timeout->clear();
|
||||||
|
|
||||||
$output_subdir = date('Ymd-His', time());
|
$output_subdir = date('Ymd-His', time());
|
||||||
$image_queue = $this->generate_image_queue();
|
$image_queue = $this->generate_image_queue();
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Rule34 extends Extension
|
||||||
global $database, $page, $user;
|
global $database, $page, $user;
|
||||||
|
|
||||||
# Database might not be connected at this point...
|
# Database might not be connected at this point...
|
||||||
#$database->set_timeout(DATABASE_TIMEOUT+15000); // deleting users can take a while
|
#$database->set_timeout(null); // deleting users can take a while
|
||||||
|
|
||||||
if (function_exists("sd_notify_watchdog")) {
|
if (function_exists("sd_notify_watchdog")) {
|
||||||
\sd_notify_watchdog();
|
\sd_notify_watchdog();
|
||||||
|
|
|
@ -180,6 +180,7 @@ class SourceHistory extends Extension
|
||||||
|
|
||||||
protected function process_bulk_revert_request()
|
protected function process_bulk_revert_request()
|
||||||
{
|
{
|
||||||
|
global $_shm_timeout;
|
||||||
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
|
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
|
||||||
$revert_name = $_POST['revert_name'];
|
$revert_name = $_POST['revert_name'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,7 +210,7 @@ class SourceHistory extends Extension
|
||||||
$revert_date = null;
|
$revert_date = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible.
|
$_shm_timeout->clear(); // reverting changes can take a long time, disable php's timelimit if possible.
|
||||||
|
|
||||||
// Call the revert function.
|
// Call the revert function.
|
||||||
$this->process_revert_all_changes($revert_name, $revert_ip, $revert_date);
|
$this->process_revert_all_changes($revert_name, $revert_ip, $revert_date);
|
||||||
|
|
|
@ -178,6 +178,8 @@ class TagHistory extends Extension
|
||||||
|
|
||||||
protected function process_bulk_revert_request()
|
protected function process_bulk_revert_request()
|
||||||
{
|
{
|
||||||
|
global $_shm_timeout;
|
||||||
|
|
||||||
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
|
if (isset($_POST['revert_name']) && !empty($_POST['revert_name'])) {
|
||||||
$revert_name = $_POST['revert_name'];
|
$revert_name = $_POST['revert_name'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -207,7 +209,7 @@ class TagHistory extends Extension
|
||||||
$revert_date = null;
|
$revert_date = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible.
|
$_shm_timeout->clear(); // reverting changes can take a long time, disable php's timelimit if possible.
|
||||||
|
|
||||||
// Call the revert function.
|
// Call the revert function.
|
||||||
$this->process_revert_all_changes($revert_name, $revert_ip, $revert_date);
|
$this->process_revert_all_changes($revert_name, $revert_ip, $revert_date);
|
||||||
|
|
|
@ -46,6 +46,8 @@ _set_up_shimmie_environment();
|
||||||
$_tracer = new \EventTracer();
|
$_tracer = new \EventTracer();
|
||||||
$_tracer->begin("Bootstrap");
|
$_tracer->begin("Bootstrap");
|
||||||
_load_core_files();
|
_load_core_files();
|
||||||
|
$_shm_timeout = new \Timeout();
|
||||||
|
$_shm_timeout->set(((int)ini_get('max_execution_time')) || 30);
|
||||||
$cache = loadCache(CACHE_DSN);
|
$cache = loadCache(CACHE_DSN);
|
||||||
$database = new Database(DATABASE_DSN);
|
$database = new Database(DATABASE_DSN);
|
||||||
$config = new DatabaseConfig($database);
|
$config = new DatabaseConfig($database);
|
||||||
|
|
Reference in a new issue