Category: PHP

Secure and Fast WordPress Self-Hosting

With the increasing centralization of personal web content into huge, monolithic entities, the traditional personal site is becoming increasingly scarce. Self-hosting your own web content used to be the rule rather than the exception, and I think that’s a loss not fully realized yet. Those centralized services are no better at preventing stale links, which has historically been the biggest…

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…

(The only proper) PDO tutorial →

An excellent resource for getting started with PDO in PHP. With the appropriate drivers installed, you can use it to access everything from MySQL to PostgreSQL and Amazon Redshift. PDO is a Database Access Abstraction Layer. The abstraction, however, is two-fold: one is widely known but less significant, while another is obscure but of most importance. Everyone knows that PDO…

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…