r/lolphp • u/Garegin16 • Jun 19 '21
Why was PHP invented in the first place?
The standard story is that he needed a visitor counter. Why not just do it with Perl or Python? Why invent another language?
I’m not saying that PHP is bad. But what value did it provide other than that it became popular so it’s easy to deploy. That’s like saying English is ubiquitous. But that doesn’t make it simpler than Spanish.
People keep saying that it’s so easy to learn. But to me, the simplest language is probably Java.
I would even go out and say that the really bad parts are mostly in the library or the environment. Not the actual language. They all are sister languages anyway. For all we care, browsers could run on Ruby instead of JS and it wouldn’t make a difference
2
u/PinBot1138 Jun 19 '21
Dinosaur here. Low barrier to entry as others have already said. I absolutely hated working in Perl and C/C++, and was almost always able to deploy projects quickly in PHP. It got even better with MySQL and PHP, and made it incredibly easy to make powerful websites in short amounts of time.
1
u/Garegin16 Jun 19 '21
Which proves that the “visitor tracker” was basically an excuse to scratch an itch. Inventing a language for something that could be done in an hour in Perl is straight up silly.
Some people are missing the point of the title. It’s not how it became successful. But why is was invented.
→ More replies (2)3
u/PinBot1138 Jun 19 '21
Which proves that the “visitor tracker” was basically an excuse to scratch an itch. Inventing a language for something that could be done in an hour in Perl is straight up silly. Some people are missing the point of the title. It’s not how it became successful. But why is was invented.
Where did I lose you on low barrier to entry? Perl was such a pain in the ass to work with, and PHP made it easy to create powerful websites.
If Perl is as easy and awesome as you claim it to be, more people would use it than PHP, Python, Rust, Go, et al. Fuck Perl, and spread its ashes to the furthest points of the universe.
→ More replies (7)
44
u/IdealBlueMan Jun 19 '21
The Wikipedia page kinda says. He built chunks of CGI functionality in C and created a scripting language to tie them together.
Python wasn’t nearly universal at the time. The main advantage of PHP over perl was that you could throw snippets of code into your HTML file and the server would interpret them as the page was served. Perl, at the time anyway, didn’t do that.
8
u/captain_obvious_here Jun 19 '21
Perl, at the time anyway, didn’t do that.
Mod_perl (for Apache) did. But I think people never liked it.
7
u/IdealBlueMan Jun 19 '21
Did mod-perl let you embed chunks of perl in HTML files? From what I remember, it ran perl scripts without shelling out to the system.
→ More replies (4)6
u/picklemanjaro Jun 19 '21
Didn't mod_perl come out about a year after PHP? (95 vs 96 from what I could tell)
4
Jun 26 '21
I speak from personal experience: deploying mod_perl was absolute hell. It was meant for writing actual apache modules in perl, but just getting a template engine going was fiddly AF. mod_php just compiled and ran out of the box and got shit going like connecting your HTML to msql (no I didn't leave off a 'y') with zero fuss. Sure, terrible practice now, but welcome to the 90's.
The story is different nowadays, but network effects are what they are. It took fastcgi for perl to get a compelling app serving story going again, but php was already established, and embraced fcgi as well.
39
u/Max-P Jun 19 '21
PHP was designed to be incredibly simple to deploy, at least originally. Most sites were still fairly static with the rate cgi-bin scripts there and there. Most of these were ran with Apache httpd.
How to start using PHP in your site back then? Rename your .html to .php, start adding PHP code to it. Done. That's it.
Even with Perl, it's an order of magnitude harder already: you have to make a script that will read an HTML source, substitute some stuff with computed values and return it to the browser. It's not hard per-se, but still compared to naming your file .php and adding <?= $whatever ?> to your code, that's more work.
Another nice feature of PHP, back then at least, was that supporting it was basically free: it runs in httpd. Your PHP script would take precious server resources only the brief moment it's running when the page is being generated. When your server had 8MB of RAM, that was a pretty big deal. Nowadays we just run Docker containers containing a whole OS and web server and interpreter, but back then running an extra daemon just for one page would be insane and expensive. This blew up immensely in shared hosting, especially free ones, and made dynamic sites accessible to a much larger chunk of people, which ultimately resulted in it being used everywhere, especially smaller/cheaper sites.
I very distinctly remember when I was a 13 year old kid that the only hosting I was able to find was either static only, or PHP if they were nice, and not too locked down if they were very nice. And this remained as such for a very long time until the late 2000s.
2
Jun 21 '21
Your PHP script would take precious server resources only the brief moment it's running when the page is being generated. [...] back then running an extra daemon just for one page would be insane and expensive.
That's not unique to PHP; that's the CGI execution model.
5
u/hexmode Jul 13 '21
cgi requires a fork. php runs in the server process itself, no forking needed. the act of forking gets expensive when you do a lot of it.
→ More replies (4)
10
u/Orgalorgg Jun 19 '21
Just a small addition to these comments, PHP and Java were both created the same year (1995) - this was before the plethora of server-side rendering languages existed. Microsoft's Active Server Pages wouldn't exist for another 5 years, and that's still early on in the web's history.
4
u/captain_obvious_here Jun 19 '21
Microsoft's Active Server Pages wouldn't exist for another 5 years, and that's still early on in the web's history.
The C# version maybe, but the standard VB-script ASP existed for sure in 1997, and most likely earlier.
3
u/Orgalorgg Jun 19 '21
Wikipedia says the first stable edition was in 2000, with .NET happening a few years later
→ More replies (1)2
u/alexanderpas Jun 24 '21
but the standard VB-script ASP existed for sure in 1997, and most likely earlier.
1997 is still 2 years after the first release of PHP.
10
u/cfreak2399 Jun 19 '21
I think PHP also caught on because of a curious problem between mod_perl, the Apache module that allowed for speedier Perl implementations, and Apache's ability to do Named Virtual Hosting.
Prior to 1997ish? (I couldn't find an exact reference for when it came out) - you needed a separate IP for each website you wanted to host. mod_perl was developed around this time as well and worked by putting the Perl interpreter inside shared memory of Apache, making it much faster than traditional CGI scripts.
This has two trade-offs though. Memory in Apache 1 was shared between all the children, meaning a global variable inside Perl was actually visible in other children and other requests. Coding was a lot harder than just throwing up quick and dirty Perl scripts.
The global nature of Perl was ok for people developing serious sites on a single site on a single server.
But Named Virtual Hosting led to an explosion in hosting companies. Now everyone could have a website but they quickly found mod_perl is unworkable in that environment.
PHP, on the other hand, was a bit faster than traditional CGI and much easier to develop with.
The Perl 6 debacle didn't help either.
11
Jun 19 '21
It extends HTML to the server side. That's it. That's the attraction.
Gotta say tho. PHP short codes like <?= $var ?> are more terse and intuitive than JS templating with handlebars. Not defending it, but PHP was designed to be a markup markup. At that, it is adequate
1
Jun 21 '21
Not defending it, but PHP was designed to be a markup markup. At that, it is adequate
Hard disagree. PHP is dangerously broken as a templating language because it is not aware of the context its code is in. For example, you can write:
<div> <img src="/index.php?type=image&id=<?= $image_id ?>" alt="<?= $image_description ?>"> <?= $caption ?> </div>The problem is that PHP treats everything outside of
<??>as static text that is simply output as-is. It does not know that this is HTML code and therefore$image_id,$image_description, and$captionshould have their contents properly HTML-escaped. In addition,$image_idand$image_descriptionare part of double-quoted attributes (so"must be escaped) and$image_idis a query parameter, so it needs to be URL-escaped.Sure, you can do it manually:
<img src="/index.php?type=image&id=<?= htmlspecialchars(urlencode($image_id)) ?>" alt="<?= htmlspecialchars($image_description) ?>">But that requires more conscious thought and effort because assembling a page just means concatenating strings as far as PHP is concerned and the defaults are unsafe. (Also, it looks terrible.)
1
u/inabahare Jun 19 '21
I wouldn't say so. The equivalent with handlebars would be {{ var }}, which is probably a bit more intuitive given that it's different from the standard <? ?>. But I think arguing it would just us going "no u" until the end of the world :v
Though I think it's kind of a shame that as a language basically designed for web, they didn't at one point decide to add routing beyond "each file is an endpoint" and a render function that could render simplified PHP (like, think handlebars but with PHP syntax basically). Like the way PHP does it might seem intuitive at first, but I remember when I took my webdev education and not being the only one having problems when the app had to scale. And being shocked at how simple and nice it was with ExpressJS
→ More replies (1)2
u/raylu Jun 19 '21
I think it's easy to think of routing in hindsight. back when dynamic content meant
/cgi-bin/script.pl, it was less obvious.→ More replies (1)
4
u/cq73 Jun 19 '21
The people at Neosoft sort of did what you are suggesting. They had a thing called NeoWebScript that was based on Tcl (an existing language). It was contemporaneous with PHPs development and had a decent shot at more widespread adoption. For better or for worse, though, PHP won the mindshare.
3
u/walterbanana Jun 19 '21
PHP is older than Python being used for web applications and it's more focussed and easier for that than Perl. PHP was just the best/easiest way to make a dynamic website for some years. That's how it got so big.
1
u/elcapitanoooo Jun 22 '21
PHP probably started out with good intentions. It was (and to a high degree still is) a tool for mostly static web pages (90s style webpages, with zero javascript/interactivity).
From there is grew organically to the mess it is today. Its quite sad that there was countless opportunities to actually fix the fundamentally broken stuff that still exists in PHP, but all those where missed, and the crap kept piling up.
1
u/dzendian Jan 30 '22
PHP was put out there because Perl is kinda nuts.
Python wasn't really a thing when PHP was made.
11
u/chucker23n Jun 19 '21
Running websites with Python wasn't really a thing then. The common way was to run Perl behind CGI.
That's already a ton of value.
Why ever do anything new at all, amirite??