On the Bigcommerce Engineering blog there's a new post sharing a few tips for memory optimization in your PHP applications. This includes tips you can implement at a code level without too many changes to the server or the need for external services.
Lately, I’ve been working on optimizing the memory of some of our backend PHP applications and wanted to share some of the tricks that I have come across, especially dealing with large set of data using PHP.
Each of their tips includes code to illustrate the technique:
- Always cap your internal in-memory caching
- Use layered caching
- (Freeing) DB Resources
- Free large blocks of memory
Some of the examples include output from the scripts showing the reduction (or non-growth) of the peak memory usage of the script.