Practical CS: Memory and Garbage Collection in PHP

Drupal Camp Asheville 2024 - July 12th-14th

Room
Hopin Sessions
Start Time

Topics

Presenter(s)

Jim Vomero
of
Four Kitchens
Jim Vomero Photo

It’s easy to forget that our programs actually run on metal; where ones and zeros are stored as charges in physical components. Modern programming languages give us a false feeling of separation from these circuit boards. Interpreted languages like PHP offer such flexibility, we often don’t consider the low-level issues, such as how our code affects memory allocation.

This beginner session explores computer science topics related to memory in PHP through practical examples. The goal is to demystify memory allocation so that we can write more efficient scripts. Topics include:

  • The basics: What is memory and where is it allocated in the PHP lifecycle?
  • Dynamic types: How ZVals allow us to change a string to an array to a boolean; and the costs associated with this flexibility.
  • Simple benchmarking: How to capture memory metrics without installing large frameworks or profiling tools.
  • Memory leaks: A look at garbage collection in PHP and how to reduce the memory consumption of our scripts.

As processors become faster, the way we use memory can be one of the greatest factors slowing down our program execution. Attendees should leave this session with a better understanding of how memory works and feel empowered to reduce their memory footprint.

Target Audience

This session is for PHP programmers of all experience levels. The content is written for developers who do not have a computer science background and may be struggling with impostor syndrome.

Learning Objectives

Attendees should leave with some best practices for declaring, scoping, and unsetting variables. They will gain a few tools for measuring performance so they can continue to explore this topic in their own work.

Prior Technical Knowledge

This is for developers who understand the basics of PHP; creating variables, functions, and blocks of code. The goal is to be accessible to all levels of programming but interesting to a wide audience as well.

Session Files

Attachment Size
Practical CS_ Memory Allocation.pdf1.06 MB 1.06 MB