Tag: Web

Memory-Efficient PHP “Arrays”

PHP arrays are sort of a combination of traditional C-style arrays (i.e., index-based lookup) and hash tables (plus a few extra bits). With this comes a decent amount of overhead — they use a lot of memory! For something as basic as an array of 64-bit integers, it uses around 152 bytes per entry: Memory usage in MB for an…

Rate Limiting in PHP with Token Bucket

PHP is largely a stateless language. With few exceptions, its environment is completely constructed from scratch for each request. Consequently, maintaining a semblance of state persistence requires a storage backend so each iteration of the environment can be initialized accordingly. Retrieving from storage is a more expensive operation than storing in active memory, so a naive approach to rate limiting…

Edge Cases – gzdecode

PHP is a language that has largely had its development driven by the real world use and demands by its users. Those users, unfortunately, have not always updated in a timely fashion, so functionality that has been implemented over multiple versions is not always fully available and can create problems for the unaware. The zlib family of functions are one…

Missing Values in PHP $_POST

I had a debugging problem recently with some server code. It involved passing a list of IP addresses and associated metadata to the central server so that list could be pulled into a different host later. The problem was that, as soon as it reached 127 IPs, everything after that was ignored. Searching for a hint on why produced very…

SSL for Multiple Domains with Apache 2

The purpose of this post is to serve as something of a catch-all how-to for hosting multiple domains with Apache 2 on a single IP with SSL enabled for all of them. I recently underwent this process with every domain I have a website behind, and doing it correctly required information from a lot of different sources. SNI Hosting multiple…