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.

Most importantly, though, PHP ran on the server – unlike the other main web-native languages, JavaScript and HTML. That meant users were able to control the code environment and be sure that the hardware was accessible, all whilst being able to use the “normal” programming logic and capabilities that software developers were used to. PHP could be used to create a simple personal website or blog, sure, but it could also be used to build complex digital applications that just happened to be hosted on the web, accessible via any browser. This functionality created a whole new set of possibilities, so it’s no wonder that PHP development took off.

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:

JavaScript is popular for the same reason PHP was popular: low barrier to entry for newcomers plus ubiquity (aka, easy to embed everywhere).

JavaScript remains popular largely due to much better evolution than PHP, which couldn’t figure out which way to grow.

Nicholas C. Zakas (@slicknet)

This can make maintenance and extensibility a problem when working with PHP, but it also means that two PHP developers may have completely different ideas of how to use the language. Whilst JavaScript and other popular languages can also fall afoul of poor engineering practices, their communities have come up with systems like TDD and tools like TypeScript to help mitigate these issues. PHP has been much slower to develop similar solutions, partially because of the lack of community consensus and partially because of differing opinions between the companies that look after the language.

At the same time, JavaScript remains the only way to truly manage a dynamic front-end, which is increasingly important in a world of web applications, Cloud services, and single-page websites (SPAs). If you’re a small company or start-up looking to create something on the web, that means you have to hire engineers with strong JavaScript experience. If you can use one language on both the front- and back-end of your platform then you may be able to make more with less – the holy grail of start-up teams. Hence, Node.js (the “.js” standing for JavaScript, FYI) becomes a much more attractive option than PHP.

So, from the perspective of a small business or start-up, Node.js can get you off the ground faster and at a lower immediate cost. But PHP is also literally slower than languages like JavaScript and Ruby. Despite being a server-side language, PHP can often be lethargic on the server, taking time to adequately render complex websites, which makes it a poor option for SPAs and dynamic front-ends. PHP also uses a now-outdated method of querying the server; a system which made sense in the more static web of the ‘90s but can now result in PHP websites feeling sluggish on modern broadband connections.

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.

All of these issues combined to create a system which simply didn’t serve the needs of the biggest web platforms, leading them to begin searching for other options or to simply create their own from scratch. Node.js was built on top of Google’s V8 JavaScript Engine, and also received early support from Microsoft. Facebook have since built out React.js and GraphQL, both of which are more naturally combined with a JavaScript back-end like Node.js, and other giants like Amazon have embraced the flexibility and speed of Node.js within their own tech stacks, meaning industry-leading services like AWS have Node.js compatibility baked in instead of PHP support.

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.

At the same time, the PHP stack remains the cheapest option for hosting, especially for small businesses not looking to become the next tech unicorn. JavaScript-powered services like Netlify and Heroku are rapidly gaining in popularity, but outside of tech circles they remain a relative unknown, with enterprise support options that are expensive when compared to traditional PHP-based web hosting platforms.

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.

Enter Swoole, a new PHP framework looking to capture a part of what Node.js did for JavaScript by offering some exciting new capabilities. First and foremost, Swoole is designed with asynchronous, event-driven programming in mind, meaning that straight out of the box several of the biggest pain points of using PHP have been removed.

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.

Graph showing PHP7 with Swoole reading files 40% faster than Node.js.

Graph showing PHP7 with Swoole filling an associative array three times faster than Node.js.

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?

Graph showing requests per second on HTTP servers running on Swoole, Nginx and Node.js. Swoole scores 6,500; Nginx 2,500; Node.js around 600.

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.”

If these types of results continue to be confirmed by a diverse range of services, Swoole could become a seriously viable alternative to Node.js and other options. In particular, companies looking to squeeze out every ounce of performance from their platforms, but who built their services in PHP originally, could have a much easier path to integrate Swoole than to rearchitect the entire platform into JavaScript.

But even more powerfully, if Swoole continues to outperform Node.js, then it could attract the attention of the very companies that popularised JavaScript back-ends in the first place. The largest tech companies are the ones that most need to optimise every inch of their codebase; a saving of up to 50% in response times is a huge margin, but at that level even a 10% gain could be worth the headache of migrating back to PHP.

A Future for PHP?

Of course, only time will tell if any of the biggest players decide to make that leap. Other factors remain which have contributed to placing PHP on the outside of tech conversations, and the ability to have a single language across the front- and back-end of a tech stack (with the team structure flexibilities that provides) remains a very strong benefit of Node.js and JavaScript in general.

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.

Illustration credit: Vecteezy

Share Article:

Copyright © 2019 - Talent Point - All rights reserved
Privacy Policy