diff --git a/common.php b/common.php index c6878ad0..d43e41b6 100644 --- a/common.php +++ b/common.php @@ -2,6 +2,7 @@ if (isset($_REQUEST['GLOBALS'])) die(); +ignore_user_abort(true); define('TIMESTART', utime()); define('TIMENOW', time()); diff --git a/library/includes/core/mysql.php b/library/includes/core/mysql.php index 2d0a7ddb..d4b103e4 100644 --- a/library/includes/core/mysql.php +++ b/library/includes/core/mysql.php @@ -254,8 +254,10 @@ class sql_db } return $result; } - - return false; + else + { + return false; + } } /** @@ -269,8 +271,10 @@ class sql_db { return isset($row[$field_name]) ? $row[$field_name] : false; } - - return $row; + else + { + return $row; + } } /** @@ -527,8 +531,10 @@ class sql_db { return array('code' => mysql_errno($this->link), 'message' => mysql_error($this->link)); } - - return array('code' => '', 'message' => 'not connected'); + else + { + return array('code' => '', 'message' => 'not connected'); + } } /** diff --git a/library/includes/cron/cron_check.php b/library/includes/cron/cron_check.php index 52920f6f..5c211ff0 100644 --- a/library/includes/cron/cron_check.php +++ b/library/includes/cron/cron_check.php @@ -22,6 +22,7 @@ if ($cron_jobs) if ($job['disable_board']) { cron_disable_board(); + sleep(10); break; } } @@ -34,4 +35,4 @@ if ($cron_jobs) else { bb_log(date('H:i:s - ') . getmypid() .' --x- no active jobs found ----------------------------------------------'. LOG_LF, CRON_LOG_DIR .'cron_check'); -} +} \ No newline at end of file diff --git a/library/includes/cron/cron_init.php b/library/includes/cron/cron_init.php index b29650e9..32c8bc94 100644 --- a/library/includes/cron/cron_init.php +++ b/library/includes/cron/cron_init.php @@ -58,6 +58,7 @@ function cron_track_running ($mode) // if (cron_get_file_lock()) { + ignore_user_abort(true); register_shutdown_function('cron_release_file_lock'); register_shutdown_function('cron_enable_board'); @@ -73,4 +74,4 @@ if (cron_get_file_lock()) if (defined('IN_CRON')) { bb_log(date('H:i:s - ') . getmypid() .' --x- ALL jobs FINISHED *************************************************'. LOG_LF, CRON_LOG_DIR .'cron_check'); -} +} \ No newline at end of file diff --git a/library/includes/cron/cron_run.php b/library/includes/cron/cron_run.php index eb168118..45660da8 100644 --- a/library/includes/cron/cron_run.php +++ b/library/includes/cron/cron_run.php @@ -114,6 +114,8 @@ foreach ($cron_jobs as $job) LIMIT 1 "); + sleep(1); + if (utime() - TIMESTART > 600) { return; // чтобы daily скрипты не блокировали надолго interval'ные @@ -124,4 +126,4 @@ foreach ($cron_jobs as $job) $cron_err_msg = "Can not run \"{$job['cron_title']}\" : file \"$job_script\" not found". LOG_LF; bb_log($cron_err_msg, 'cron_error'); } -} +} \ No newline at end of file diff --git a/library/includes/cron/jobs/board_maintenance.php b/library/includes/cron/jobs/board_maintenance.php index 0e33dde1..fb14a1b1 100644 --- a/library/includes/cron/jobs/board_maintenance.php +++ b/library/includes/cron/jobs/board_maintenance.php @@ -31,6 +31,10 @@ if ($poll_max_days = (int) $bb_cfg['poll_max_days']) { break; } + if (!($start_id % ($per_cycle*10))) + { + sleep(1); + } $start_id += $per_cycle; } } @@ -42,4 +46,4 @@ DB()->query("UPDATE ". BB_USERS ." SET user_newpasswd = '' WHERE user_lastvisit if ($posts_days = intval($bb_cfg['posts_cache_days_keep'])) { DB()->query("DELETE FROM ". BB_POSTS_HTML ." WHERE post_html_time < DATE_SUB(NOW(), INTERVAL $posts_days DAY)"); -} +} \ No newline at end of file diff --git a/library/includes/cron/jobs/prune_inactive_users.php b/library/includes/cron/jobs/prune_inactive_users.php index 16baff11..a170d816 100644 --- a/library/includes/cron/jobs/prune_inactive_users.php +++ b/library/includes/cron/jobs/prune_inactive_users.php @@ -52,4 +52,6 @@ while (true) { break; } -} + + sleep(3); +} \ No newline at end of file diff --git a/library/includes/cron/jobs/sessions_cleanup.php b/library/includes/cron/jobs/sessions_cleanup.php index 6518560d..81ea0c84 100644 --- a/library/includes/cron/jobs/sessions_cleanup.php +++ b/library/includes/cron/jobs/sessions_cleanup.php @@ -34,6 +34,8 @@ DB()->query(" DB()->unlock(); // ############################ Tables UNLOCKED ############################## +sleep(5); + // Delete staled sessions DB()->query(" DELETE s @@ -42,4 +44,4 @@ DB()->query(" (s.session_time < $user_session_gc_time AND s.session_admin = 0) OR (s.session_time < $admin_session_gc_time AND s.session_admin != 0) -"); +"); \ No newline at end of file diff --git a/library/includes/cron/jobs/tr_make_snapshot.php b/library/includes/cron/jobs/tr_make_snapshot.php index 28577c60..7f504118 100644 --- a/library/includes/cron/jobs/tr_make_snapshot.php +++ b/library/includes/cron/jobs/tr_make_snapshot.php @@ -83,6 +83,11 @@ while (true) break; } + if (!($start_id % ($per_cycle*10))) + { + sleep(1); + } + $start_id += $per_cycle; } @@ -197,4 +202,4 @@ if ($bb_cfg['torhelp_enabled']) DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_TORHELP .", ". OLD_BB_BT_TORHELP); } -DB()->expect_slow_query(10); +DB()->expect_slow_query(10); \ No newline at end of file diff --git a/library/includes/functions_admin_cron.php b/library/includes/functions_admin_cron.php index 1b7c7ba4..b1464f19 100644 --- a/library/includes/functions_admin_cron.php +++ b/library/includes/functions_admin_cron.php @@ -41,6 +41,7 @@ function run_jobs($jobs) END WHERE cron_id IN ($jobs) "); + sleep(3); return; } @@ -153,4 +154,4 @@ function update_cron_job($cron_arr) run_counter = '$run_counter' WHERE cron_id = $cron_id "); -} +} \ No newline at end of file diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index f073e65a..7c391262 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -677,11 +677,16 @@ function ocelot_send_request ($get, $max_attempts = 1, &$err = false) global $bb_cfg; $header = "GET /$get HTTP/1.1\r\nConnection: Close\r\n\r\n"; - $attempts = $success = $response = 0; + $attempts = $sleep = $success = $response = 0; $start_time = microtime(true); while (!$success && $attempts++ < $max_attempts) { + if ($sleep) + { + sleep($sleep); + } + // Send request $file = fsockopen($bb_cfg['ocelot']['host'], $bb_cfg['ocelot']['port'], $error_num, $error_string); if ($file) @@ -689,12 +694,14 @@ function ocelot_send_request ($get, $max_attempts = 1, &$err = false) if (fwrite($file, $header) === false) { $err = "Failed to fwrite()"; + $sleep = 3; continue; } } else { $err = "Failed to fsockopen() - $error_num - $error_string"; + $sleep = 6; continue; } diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index 1b1a186e..495c384e 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -480,7 +480,10 @@ if ((empty($_POST) && !defined('IN_ADMIN') && !defined('IN_AJAX') && !file_exist if (DB()->get_lock('cron', 1)) { bb_log(date('H:i:s - ') . getmypid() .' --x- DB-LOCK OBTAINED !!!!!!!!!!!!!!!!!'. LOG_LF, CRON_LOG_DIR .'cron_check'); + + sleep(2); require(CRON_DIR .'cron_init.php'); + DB()->release_lock('cron'); } }