Created
July 6, 2013 19:38
-
-
Save atannus/5940994 to your computer and use it in GitHub Desktop.
Quick hack to allow Kohana to handle memory_limit and max_execution_time violations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Kohana extends Kohana_Core { | |
/** | |
* Augments the core method for two reasons: | |
* 1) Reserve an extra 1M memory to allow handling memory_limit violation. | |
* 2) Reserve more exec time to allow max_execution_time violation. | |
* | |
* Note: keep variable creation at a minimum. | |
* | |
* @return void | |
* @author Andre Tannus | |
*/ | |
public static function shutdown_handler() | |
{ | |
# Increase allowed execution time | |
set_time_limit(10); | |
# Increase allowed memory limit | |
# Get current memory limit | |
$memory_limit = trim(ini_get('memory_limit')); | |
switch( strtolower(substr($memory_limit, -1, 1) ) ) | |
{ | |
case 'g': $memory_limit *= pow(1024, 3); break; | |
case 'm': $memory_limit *= pow(1024, 2); break; | |
case 'k': $memory_limit *= pow(1024, 1); break; | |
} | |
# Request an extra 1M. Reuse variable. | |
$memory_limit += 1024*1024; | |
ini_set('memory_limit', $memory_limit); | |
# Call the original handler | |
parent::shutdown_handler(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment