Skip to content

Instantly share code, notes, and snippets.

@Leko
Last active December 14, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leko/025b4d7fa192b106ea51b9078f31e749 to your computer and use it in GitHub Desktop.
Save Leko/025b4d7fa192b106ea51b9078f31e749 to your computer and use it in GitHub Desktop.
PHP memory limit dealing when memory limit exceeded
<?php
class SomeClass {
public function __destruct ()
{
echo __FILE__.':'.__LINE__.PHP_EOL; // Not working
}
}
register_shutdown_function(function () {
echo __FILE__.':'.__LINE__.PHP_EOL; // It works
});
$instance = new SomeClass;
echo __FILE__.':'.__LINE__.PHP_EOL; // It works
range(0, 1000000000000);
$ php -v
PHP 5.6.20 (cli) (built: Apr 28 2016 15:56:12)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
$ php memory-over.php
/Users/inoue.shingo/Downloads/memory-over.php:16
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /Users/inoue.shingo/Downloads/memory-over.php on line 18
/Users/inoue.shingo/Downloads/memory-over.php:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment