The History of the Web logo

Unraveling the web's story


The History of Rewriting PHP

If you work on the web, you know that with software, things don’t always go right the first time. The web is this massive, global community tinkering with loosely connected technologies to piece together websites that, with any luck, work well together. These tools and technologies are always in flux and there have been plenty of stops, starts, and restarts. More often than not, a restart involves what’s referred to as a rewrite. This means that software is dismantled down to its core, and then put back together piece by piece in a way that (hopefully) vastly improves things for the people using it. On the web, things move so fast that rewrites are happening almost all the time.

PHP version 3 was one of those times.

In 1997, Andi Gutmans and Zeev Suraski decided that they were going to use PHP for their college coding project. Their university was in Tel Aviv and their assignment was to build an e-commerce shopping cart. Their teacher knew that PHP was still more or less an untested technology. She suggested that they try something different, something that was a bit more proven out, especially for something so advanced. But Gutmans and Suraski stubbornly refused and stuck with PHP.

Within the first few hours of getting started, they realized she had been right. They ran into one weird quirk in the code they were writing. Then another. After investigating a bit, they found that the problem wasn’t with their own code, it was embedded deep inside the PHP source code. There was basically no way to make it work, and therefore no way to finish the shopping cart. Thankfully, their teacher showed mercy and let them switch things up. Instead of a simple shopping cart, they would rewrite all of PHP from the ground up.

The announcement of PHP 3

A lot of times, this is exactly how a rewrite get’s started. An active developer gets fed up enough with some software or tool or programming language and decides to give the whole thing another go. You’d just have to ask the creator of PHP. Because he did basically the same thing on more than one occasion.

The first major rewrite of PHP happened way back in 1995. Before Gutmans and Suraski even began working with the software, it would go through several more. The history of PHP is the history of changes and progression that stretches back to the early days of the web.

And if you trace it back far enough, you’d find that it at all started with CGI scripts.

Way back in the NCSA Mosaic days, when the web was first beginning to spread, some developers found themselves hitting the same wall again and again. HTML pages are static by design. If you give a browser an HTML document, it will render it exactly the same every single time. There’s no way to change the content before it hits the browser, and no way to update it once it’s on the page (Javascript was barely a thought at this point). This makes HTML approachable and easy to use which fit right in line with the web’s general mantra. But it could also be rather limiting if you wanted to, say, update a stock ticker or pull some data from a form.

To solve that particular issue, the folks at NCSA cooked up a Common Gateway Interface (CGI), first released in 1993. CGI allowed developers to use advanced programming languages, like C or Perl, to process and generate dynamic HTML. The technical specifics are far from important. What is important is that CGI gave programmers the ability to change the HTML of a webpage in more or less real time, so they could do things like keep sections of a webpage up to date, or process form submissions, or add comments to a blog post. All of the things that require the content of a webpage to update from its original version.

Rasmus Lerdorf was among CGI’s earliest adopters, and began tinkering with it not long after its release. He adapted some code he wrote to run using CGI on his personal website, mostly just to track the number of visitors coming to his site. Thinking there might be some others that would benefit from his work, and generally being an advocate of an open and free exchange on the web, Lerdorf packaged up some of the tools he had been working on and released his code to the public under the moniker “Personal Home Page Tools” in June of 1995. It went by PHP Tools for short.

His hope was that a few people might find the code useful. In truth, a small community of developers began to congregate around the tools, tweaking them for use in their own sites or projects. Some people even began contributing some code back to the project.

When Lerdorf realized he was on to something, PHP got its first major rewrite. Lerdorf got started on a rewrite almost immediately after PHP Tools’ initial release. In October of 1995, Lerdorf, with the help of a few other developers, got together a new, more unified version of the software. It went by a few names, “Personal Home Page Construction Kit” and for a brief time, just “FI (Forms Interpreter)”, but at its core it remained basically tools built on top of CGI.

Screenshot of E-Trade website from around 1998
E-Trade was an early adopter of PHP

This, however, would not last long. As more and more users began to use the software, Lerdorf once again realized that what he wrote wasn’t quite enough. People were actually using his loosely connected bundle of scripts as a replacement for a full-on programming language. For the geeks out there, that meant it wasn’t a combination of “C and PHP Tools” it was just “PHP Tools.” The software was stuck between two worlds. On the one hand, it was an extremely powerful CGI tool. But on the other, it was a sorely lacking programming language.

It was time for another PHP rewrite (that’s number 3 for those following along). In the spring of 1996, Lerdorf released an entirely new version of his tool, this time called PHP/FI. It was the first version of the tool that could actually stake a claim as a programming language, and went beyond just some dynamic content on a webpage. PHP/FI allowed developers to connect to a database, and process form data, and even extend the language with their own functions.

PHP/FI gained a bit of a following. It was pretty approachable as far as programming languages go, and it was specifically pieced together for the dynamic web. That had a kind of appeal for a growing number of developers that were focusing exclusively on the web. It’s also the version that caught the attention of Gutmans and Suraski.

Actually, Gutmans and Suraski, were using PHP/FI 2.0. As had become a bit of a tradition, shortly after the initial release of PHP/FI, Lerdorf once again got to work completely rewriting some of the underlying technologies of the tool. By the time the two students started tinkering with it in 1997, it had already been released as version 2.

Fast forward to the university project. Gutmann and Suraski were now tasked with once again approaching a rewrite of PHP. They got in contact with Lerdof and other developers that had been working on the project all along, and basically gathered some intel on where everything had come from and where it should go. They also set a few goals for themselves, which Suraski later related in an interview:

– Create a ‘real’ language, based on statements, expressions, and association rules, which was a big break from PHP/FI 2.

– Make it easy to extend by adding functionality to PHP/FI 2. This required changes to the parser and scanner, and generally speaking, it was quite a difficult task. We wanted to create a base that people would be able to easily contribute to and extend.

– Make it go much faster

– Do all of that while not flunking our university courses.

After a few months, they sent a completely rewritten parser for PHP over to Lerdorf. He was impressed enough to gather together a few more developers who had been actively working on the language to pull something new together. By the end, they actually managed to check all of Suraski’s boxes.

In June of 1998, PHP version 3 was officially released. It was faster, it took lessons from object oriented programming, cleaned up bugs, and added all sorts of new features. The language was renamed once again, briefly becoming “Professional Home Page Tools” before finally settling on just the recursive acronym, dropping all pretense to just become PHP.

An early example of a PHP based forum called Phorum

If you work with PHP at all, version 3 is probably the earliest version you’d recognize. A lot of work that was done at the time managed to stick around, even to today. Before ti’s release, PHP/FI was running on around 60,000 websites. Within a year and a half, that number would jump to half a million.

Of course, this wouldn’t be the last rewrite of PHP. The language is still actively maintained, and received a pretty much major update a couple of years ago. Estimates put the number of websites that use PHP somewhere around 80% of all websites. It might have taken a while to get there, but eventually PHP was able to grab a foothold, and it hasn’t let go since.

Sources



One response to “The History of Rewriting PHP”

  1. […] and server-side dynamic content required server-side technologies like Common Gateway Interface (CGI) and numerous others such as Java Server Pages (JSP), Microsoft Active Server Pages (ASP) and more […]

Leave a Reply

Your email address will not be published. Required fields are marked *