How memory works in PHP and its hidden costs
DrupalCon Nashville 2018 Session
Join Shawn McCabe, Acro Media CTO, as he goes behind the scenes and teaches a bit about how PHP uses memory when it runs your code. PHP's ease of use and low barrier to entry also have some side effects on how memory is used, sometimes using memory differently and in places, you didn't expect. If you're doing small pages that load quickly, this probably won't even be noticeable for a low-traffic site unless things go quite wrong. Once you get into heavy pages on high traffic sites, or even worse, long-running background processes, then knowing a bit more about the memory you're using can help a lot.
In PHP, variables have a lot of metadata they need to store since they can be any size and of any type. They need all this metadata to store information like how much data they hold, what type of data it is and how it is stored. This "hidden" metadata cost will often use more memory than the actual info you are storing, although recent versions of PHP have improved on this.
The idea isn't to learn every low-level detail, just to have a little knowledge of what is happening with memory usage when you're programming so you can be cognizant of the choices you make and a bit more efficient in your usage.
Hopefully, this talk will be interesting to novice and experienced developers alike, but you only need some programming basics to follow along.
Talk to us
Acro Media is a Drupal Commerce development agency that specializes in enterprise-level ecommerce. We are committed to building strong strategic partnerships and using our ecommerce expertise to help clients create a dynamic web presence that engages audiences, generates revenue, and boosts brand awareness.