So there I was, profiling one of our systems with XHProf and what jumped out as taking up lots of wall-clock execution time? uniqid(). This function, which provides a convenient way to generate unique identifiers, can hold up your PHP execution far more than it should if you’re not careful.
Two things about uniqid() make it a potential performance minefield:
- If not called with a second argument of TRUE (the “more entropy” argument), uniqid() sleeps for at least a microsecond.
- uniqid() relies on the system function gettimeofday() — and the Linux kernel essentially serializes access to gettimeofday() across all cores.
Continue reading “uniqid() is slow”
We run PHP inside of Apache 2. This works great for servicing user requests, but that very request/response nature of the PHP setup makes it difficult to do things such as:
Continue reading “Sidekick – Using Node.js to run scheduled tasks for a service”
Plenty has been written about HTML5’s spiffy postMessage() method, which allows a window to send a text string to another window. When one of those windows is a web page in one domain, and another one of those windows is an iframe for a different domain embedded in the first window, you’ve got the basis for cross-domain communication that can work around the restrictions of traditional Ajax requests.
To take advantage of this capability, I put together a proof-of-concept jQuery plugin that makes this pretty simple.
Continue reading “Cross-domain communication with HTML5 postMessage”
Our build and deployment toolchain is:
- git for version control
- Maven for packaging and dependency management
- Nexus for artifact management
- Pulse for automated build management
- galaxy for deployment
Continue reading “Building Non-Java Stuff With Maven and Friends”
We added a language filter to Ning Pro last month. It lets Network Creators have naughty words (for the Network Creator’s definition of “naughty”) replaced with * characters.
A straightforward way to do this in PHP is to pass an array of words to look for and their replacements to a function like str_replace() or str_ireplace(). Or, similarly, use a regular expression that gloms the search terms together (and potentially checks word boundaries.) There are assorted WordPress plugins that work like this.
Continue reading “Fast multiple string replacement in PHP”
I’m pleased to announce the release of ub, a PHP microbenchmarking framework. You can download it from http://github.com/ning/ub.
The goal is to make it as easy as possible to compare the runtime of alternative approaches to the same problem, such as different regular expressions, or different methods for string or array manipulation.
Continue reading “PHP Microbenchmarking”
There are several popular JS benchmarks out there, such as the SunSpider benchmark suite that’s part of the WebKit project and the V8 Benchmark suite.
These benchmarks cover a variety of tasks that are a mix of typical-things-a-browser-might-need-to-do and assorted CPU-heavy activities.