Skip to content

[5.8] Allocate memory for error handling to allow handling memory exhaustion limits#29226

Merged
taylorotwell merged 2 commits into
laravel:5.8from
skylerfenn:5.8
Jul 21, 2019
Merged

[5.8] Allocate memory for error handling to allow handling memory exhaustion limits#29226
taylorotwell merged 2 commits into
laravel:5.8from
skylerfenn:5.8

Conversation

@skylerfenn

Copy link
Copy Markdown
Contributor

Allots 10kb of memory for "memory exhaustion" errors.

It lets the application give a more descriptive error than the default Fatal Error that is thrown for memory exhaustion.

The concept was taken from Symfony's error handler: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/ErrorHandler/ErrorHandler.php.

@driesvints driesvints changed the title Allocate memory for error handling to allow handling memory exhaustion limits [5.8] Allocate memory for error handling to allow handling memory exhaustion limits Jul 19, 2019
@taylorotwell

Copy link
Copy Markdown
Member

Provide before and after screenshots of the difference in error messages please.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This solution won't work, however, in the case that this method is called more than once?

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Is setting to null actually guaranteed to release the memory. How does PHP calculate this? Do we have to wait for the garbage collector?

@laurencei

Copy link
Copy Markdown
Contributor

Also - whats the performance hit (if any) on running the 'x' repeat command 10240 times? Both in terms of time and memory?

@skylerfenn

Copy link
Copy Markdown
Contributor Author

@taylorotwell
Current Error
current error

Better Error
better error

@GrahamCampbell
The bootstrap method will only run each bootstrapper once on a request:
https://github.com/laravel/framework/blob/5.8/src/Illuminate/Foundation/Http/Kernel.php#L161

From what I've been able to see, setting a variable to null frees the memory immediately.

@laurencei
The function is only running once with 1 byte. The PHP source for str_repeat shows: "Heavy optimization for situations where input string is 1 byte long". Do you know of a more efficient way to allocate 10kb? Again, this idea was taken from Symfony's error handler. Throughout the history of that project, I couldn't find any discussion on this.

Thanks for the feedback and comments!

@mfn

mfn commented Jul 20, 2019

Copy link
Copy Markdown
Contributor

I like this approach, very useful.

Though I would find it really nice if there was a bit of documentation on the proper on what it is for.

@skylerfenn do you think you could add that?

@taylorotwell taylorotwell merged commit 805450a into laravel:5.8 Jul 21, 2019
@cxlblm

cxlblm commented Aug 1, 2019

Copy link
Copy Markdown
Contributor

Memory is very expensive. Is that really reasonable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants