Can Swoole Power a PHP Resurgence?
Take a look back to the state of the tech industry in 2013 and you’ll see a landscape where PHP was used by almost two fifths of development projects (35%) and powered a majority of major websites. Fast forward to 2019, and just under 26% of professional developers are using the language actively – a decline which doesn’t appear to be ending any time soon.
“Many of those who use [PHP] say they will decrease usage over the next 12 months.”
That’s the news coming out of the 2019 Node.js user survey, one of the most comprehensive datasets on back-end engineering trends. Node.js is particularly relevant to this discussion, as its sudden and widespread adoption in the mid-2010s has been the main catalyst for that shift in numbers. During that same six-year period surveyed above, Node.js usage by engineering teams skyrocketed from 7.5% to finally breaking the 50% mark in 2019; a huge gain in such a short time. So, what happened? To understand that, we first need to look at why PHP was popular in the first place.
The Rise of PHP: Powering 80%+ of the Web
PHP was originally created in the early 1990s, right as the world wide web was taking its first steps into the public consciousness. Built on the popular C programming language, the idea behind PHP was to make creating dynamic websites much, much easier; easy enough for businesses to actually invest in the technology. To say that the internet is hard-baked into PHP would be an understatement, with the acronym even deriving from the phrase “Personal Home Page” (though that would later be changed to the far more ambiguous “PHP: Hypertext Preprocessor” used today).
That web-native approach to designing a programming language gave PHP a huge amount of power, abstracting out complex ideas such as transferring files and sending emails into simple one-line functions through inbuilt support for the first web APIs. It also shared a common syntax structure with HTML, making it stylistically fit easily within existing web pages.
Early success put PHP in a good place, but it had rivals in Java, ASP.NET, and other C-based languages. It wouldn’t grow to near total dominance until the turn of the century and the creation of WordPress, a content management system that was free, intuitive, and extremely popular. Most people have heard of WordPress, even if they aren’t involved in front-end or web development, and the CMS continues to power a huge number of popular and personal websites today.
Crucially though, WordPress and the dozens of clones and competitors that it spawned were almost entirely written in PHP. Suddenly, if you wanted to build a website that leveraged all of the features of a modern CMS, you had almost no choice but to use PHP. By 2017, over 83% of the web ran on PHP, with WordPress alone accounting for nearly a third of that number.
From Hero to Zero?
Unfortunately, 2017 also saw the first time in over a decade when PHP usage statistics began to drop. Having begun to plateau, largely due to market saturation, trends in the start-up world which involved exploring other options began to be adopted by Big Tech firms like Facebook and Google – the latter of which having already created the underlying technology of Node.js almost a decade earlier.
The big impetus behind that break from the norm were the increasingly Agile practices required to fuel the rapid, iterative product development that VCs and other backers required. Put simply: PHP was too slow.
On the one hand, both the language and the development knowledge needed are restrictive if you’re trying to build software with the least amount of time and developers possible. Despite its mature and highly active community, PHP has always struggled to settle on clear engineering best practices, which means one PHP codebase can look very different to another:
Nicholas C. Zakas (@slicknet)
It also struggles to scale that well, with each active connection consuming a single server resource and routing all requests and data through that one channel. That’s fine until your service gets a traffic bump thanks to a positive review or organic promotion from a prominent influencer; these moments can be make-or-break and need to be capitalised on, but PHP servers can simply fail. More modern systems like Node.js instead utilise a technique known as asynchronous programming, which allows multiple connections per instance, creating a much more stable and scalable system.
The result is a self-fulfilling prophecy: as tooling and frameworks advance and enable greater levels of functionality through Node.js, PHP becomes increasingly slow and outdated in comparison, reducing its use and resulting in less demand for it to be supported by yet further new tools.
A Light on the Horizon: Swoole
From all of the above, the conclusion may seem clear: PHP is dying. Don’t invest in the technology, try to refactor or replatform existing services away from the language, and forget about teaching it at bootcamps or degrees. Right? Well, that’s certainly a prevalent opinion, but it’s not a definitive one.
For one thing, those 80% of websites running PHP in 2017? The vast majority of them are still sitting on PHP stacks. Usage may be dropping, but it still sits at around 79% globally, which means a huge number of companies and services will need PHP developers for years to come. Similarly, WordPress may be sliding from dominance, but it still powers around 30% of the internet and most of its direct competition remains other PHP-powered services like Drupal or Craft.
What all of that means is simple: there’s still plenty of money in PHP. That means there’s a growing number of tech innovators looking to address the issues that have resulted in the decline of the language head-on, creating new tooling that they hope will swing the needle.
The marketing promise being made is that Swoole is much more scalable, performant, and stable than anything we’ve seen for PHP before. Incredibly, initial tests appear to be backing up those claims.
The following two graphs come from a fairly simplistic set of direct comparison tests, but highlight some very interesting results. Whether performing a run-of-the-mill task such as reading a file, or attempting something more computationally difficult like filling associative arrays, Swoole consistently comes out on top, sometimes by significant margins.
Another often-cited test checked to see how well Swoole fared against another key talking point of Node.js: being able to power an HTTP server directly. The result?
Once again, Swoole came out far ahead of Node.js, but in this instance also showed substantial improvement over the current golden boy of HTTP servers, Nginx, as well. Though the author of that test does go on to point out that putting any strain on the HTTP server saw Swoole’s lead significantly decline, he still marked his surprise at initial performance:
“I didn’t expect Swoole to overtake NGINX, but it actually did! Node was outdistanced.”
A Future for PHP?
It’s also nearly impossible to predict how languages and frameworks will evolve, meaning that in less than six months a new version of Node.js could be released which closes that performance gap or even pushes past it.
That said, it no longer feels impossible that we might see a PHP resurgence. There’s a huge amount of demand out there, both for companies to create innovative tools like Swoole to tap into the still-sizeable PHP market, and for the highly trained (and often comparatively underpaid) talent that wants to get back to innovating using the skills they already have. The competitiveness of PHP is, for the first time in years, on the rise, so talk about the death of one of the web’s oldest languages might yet prove to be incredibly immature.