redfort Posted September 6, 2010 Share Posted September 6, 2010 Hi , As you may all have experienced this problem is there way we can non-healthy exit of script ..due to memory problem........??? I got to know..we avoid this......by properly managing our php memory by unset function. remove unusable variables and objects from memory......and increasing memory limit in phph.ini Is there any way we can check each time inside the script -to check memory is available or sleep for some time and check again.......to proceed without exit........ Is there a way to catch this fatal error and take necessary steps to avoid exit........ Thanks, redfort Quote Link to comment https://forums.phpfreaks.com/topic/212651-solution-to-fatal-error-allowed-memory-size-of-67108864-bytes-exhausted/ Share on other sites More sharing options...
Zyx Posted September 6, 2010 Share Posted September 6, 2010 There is a function that allows you to check the currently allocated memory: http://php.net/manual/en/function.memory-get-usage.php However, you cannot spawn a background task to control it, because PHP scripts are not multithreaded. Asking PHP for this 1000 times during the execution is also a bad idea. You cannot catch this kind of fatal error, too - how do you think it should work, if the memory is already exhausted? If your script requires so much memory, track it with XDebug and simply try to optimize it. Learn some memory-saving techniques, better algorithms, how does garbage collection in PHP work, etc. Quote Link to comment https://forums.phpfreaks.com/topic/212651-solution-to-fatal-error-allowed-memory-size-of-67108864-bytes-exhausted/#findComment-1108014 Share on other sites More sharing options...
bob.newtek Posted September 30, 2010 Share Posted September 30, 2010 As has already been posted, the first step is to try to understand how your code is using memory and try to optimize accordingly, and it sounds like you're already doing a good bit of this. However much you optimize, one of the key goals you should try to achieve is using memory predictably. Once you can accurately predict approximately how much memory your code will require, you can adjust the server configuration (physical RAM and PHP max allocation in php.ini) as needed. One other thing to keep in mind is that there's a line between optimizing code and increasing physical resources, and where the line is will depend on how important the app is to your company, how much money you have available to spend on the server(s), how valuable developer time is compared to the costs of hardware and associated maintenance, and so forth. Obviously, every situation puts the line in a unique spot. But, don't lose site of this and, for example, spend a ton of money on time trying to optimize for additional milliseconds when you can spend a small amount simply adding RAM to the server, or too much money throwing hardware at a problem easily solved in software. Quote Link to comment https://forums.phpfreaks.com/topic/212651-solution-to-fatal-error-allowed-memory-size-of-67108864-bytes-exhausted/#findComment-1117431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.