MDL-24751 fixed default memory limit when deciding to use apache_child_terminate(), apache_child_terminate() is now called from one place only

This commit is contained in:
Petr Skoda 2010-10-19 10:00:29 +00:00
parent a4c3fc813a
commit c22473a214
9 changed files with 13 additions and 44 deletions

View File

@ -68,10 +68,7 @@ if ($formdata = $mform->get_data()) {
// that we'll take longer, and that the process should be recycled soon
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("192M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
raise_memory_limit(MEMORY_EXTRA);
// Create a unique temporary directory, to process the zip file
// contents.

View File

@ -25,13 +25,7 @@ $choices = array(UU_ADDNEW => get_string('uuoptype_addnew', 'admin'),
UU_UPDATE => get_string('uuoptype_update', 'admin'));
@set_time_limit(3600); // 1 hour should be enough
@raise_memory_limit('256M');
if (function_exists('apache_child_terminate')) {
// if we are running from Apache, give httpd a hint that
// it can recycle the process after it's done. Apache's
// memory management is truly awful but we can help it.
@apache_child_terminate();
}
raise_memory_limit(MEMORY_EXTRA);
require_login();
admin_externalpage_setup('uploadusers');

View File

@ -101,9 +101,6 @@ if ($formdata = $mform->get_data()) {
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("192M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
// use current (non-conflicting) time stamp
$importcode = get_new_importcode();
@ -209,9 +206,6 @@ if ($formdata = $mform->get_data()) {
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("192M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
// we only operate if file is readable
if ($fp = fopen($filename, "r")) {

View File

@ -45,9 +45,6 @@ require_capability('gradeimport/xml:view', $context);
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("256M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
$text = download_file_content($url);
if ($text === false) {

View File

@ -49,9 +49,6 @@ if ($data = $mform->get_data()) {
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("256M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
if ($text = $mform->get_file_content('userfile')) {
print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'));

View File

@ -334,12 +334,6 @@ function cron_run() {
//Perhaps a long time and memory could help in large sites
@set_time_limit(0);
@raise_memory_limit("192M");
if (function_exists('apache_child_terminate')) {
// if we are running from Apache, give httpd a hint that
// it can recycle the process after it's done. Apache's
// memory management is truly awful but we can help it.
@apache_child_terminate();
}
if (file_exists("$CFG->dirroot/backup/backup_scheduled.php") and
file_exists("$CFG->dirroot/backup/backuplib.php") and
file_exists("$CFG->dirroot/backup/lib.php") and

View File

@ -8847,29 +8847,28 @@ function fullclone($thing) {
* should be set via register_shutdown_function()
* in lib/setup.php .
*
* Right now we do it only if we are under apache, to
* make sure apache children that hog too much mem are
* killed.
* @return void
*/
function moodle_request_shutdown() {
global $CFG;
// help apache server if possible
if (function_exists('apache_child_terminate')
&& function_exists('memory_get_usage')
&& ini_get_bool('child_terminate')) {
if (empty($CFG->apachemaxmem)) {
$CFG->apachemaxmem = 64*1024; // default 64MB
}
if (memory_get_usage() > (int)$CFG->apachemaxmem) {
trigger_error('Mem usage over $CFG->apachemaxmem: marking child for reaping.');
$apachereleasemem = false;
if (function_exists('apache_child_terminate') && function_exists('memory_get_usage')
&& ini_get_bool('child_terminate')) {
$limit = (empty($CFG->apachemaxmem) ? 64*1024*1024 : $CFG->apachemaxmem); //64MB default
if (memory_get_usage() > get_real_size($limit)) {
$apachereleasemem = $limit;
@apache_child_terminate();
}
}
// deal with perf logging
if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
if ($apachereleasemem) {
error_log('Mem usage over '.$apachereleasemem.': marking Apache child for reaping.');
}
if (defined('MDL_PERFTOLOG')) {
$perf = get_performance_info();
error_log("PERF: " . $perf['txt']);

View File

@ -448,7 +448,7 @@ if (function_exists('gc_enable')) {
gc_enable();
}
// For now, only needed under apache (and probably unstable in other contexts)
// Register default shutdown tasks - such as Apache memory release helper, perf logging, etc.
if (function_exists('register_shutdown_function')) {
register_shutdown_function('moodle_request_shutdown');
}

View File

@ -108,9 +108,6 @@ if (!$formdata = $form->get_data()) {
// to free up memory.
@set_time_limit(0);
@raise_memory_limit("96M");
if (function_exists('apache_child_terminate')) {
@apache_child_terminate();
}
$iid = csv_import_reader::get_new_iid('moddata');
$cir = new csv_import_reader($iid, 'moddata');