Live data from Hacker News

How come PHP seems so much faster than Rust?

reddit.com

71–80 of 116 posts

Re: How come PHP seems so much faster than Rust?

#71
post #20

Earlier quoted context omitted.

It’s really easy to write PHP, which means that people who don’t know about escaping input write PHP. While there are some web-focussed languages (vs frameworks) that deliberately make it hard for you to write that sort of code, barely anyone uses them.

"escaping input" is a notorious delusion. And a bad one. - it is not "input" must be treated , but, so to say - output. It's the destination that matters, not the source. By the time you get the input, you have no idea how and where it will be used. You can tell it right before the output (or, rather, better to call it "use") only. Say, you've got some input that didn't pass the verification and you will have to disp…

You're right, my wording was inexact - we must always escape strings that can be controlled in some fashion by the user.

I'm working on comprehensive taint analysis for PHP[0], and I'm spending a bunch of time thinking about how to automatically detect those dirty strings.

[0] https://psalm.dev/articles/psalm-3-and-a-half#taint-analysis

Re: How come PHP seems so much faster than Rust?

#72

Earlier quoted context omitted.

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

Indeed. I think most developers don't understand how amazing PHP was compared to the competition and just how fast it acquired new features during those early years. It was a scripting engine with a such a thin layer of C that it could easily and quickly incorporate the huge number of open source C libraries that existed at the time.

> I think most developers don't understand how amazing PHP was compared to the competition and just how fast it acquired new features during those early years.

The only competition in those early years was Perl iirc.

I'm not entirely sure if PHP was fast at acquiring new features.

PHP didn't have classes until version 4 iirc. Namespace in 5.4? And 5.x is around NodeJS early days where RoR and Python Django/Pylon/Pyramid was around.

I think how easy it is to pick up the language to do things contributed to its success. The template is built-in and 1000 functions in the global namespace.

Re: How come PHP seems so much faster than Rust?

#73
post #11

While this discussion boils down to the efficiency of the underlying regex engines for PHP and Rust, it does highlight (to me) why PHP is so popular: in the hands of average programmers, PHP is quick to write and fast (enough) to execute. I personally believe it's ubiquity is well-deserved, and I actually like it as a language despite all its quirks (which exist in almost every language I've come across)!

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

for how long? Perl existed when php started, as well as all the proprietary languages, java , asp etc. then came ruby python etc. It's not for the lack of competition

Re: How come PHP seems so much faster than Rust?

#74

Earlier quoted context omitted.

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

>for a long while [PHP] was the only viable language for developing web applications. That is not what I remember. CGI existed before PHP (1994), and was used extensively for web apps (ebay still appears to use it to this day). Also, mod_perl and Java Servlets were introduced around the same time, circa 1996, so I don't think it's correct to say PHP had a monopoly on web apps "for a long while".

I think rasmus's presentation explained pretty clearly why PHP won. Mod_php was a game changer and mod_perl failed by making the wrong choices. Overall, PHP was faster, easier, cutting edge and full of features without becoming too expensive to run, thats why web hosts supported it, not the other way around. What's not to love, honestly, even today.

https://www.youtube.com/watch?v=wCZ5TJCBWMg

Re: How come PHP seems so much faster than Rust?

#75
post #5

This is a little silly. The two programs are so simple that it's probably just testing the speed of the regex engines used by the two languages. Since PHP uses PCRE (a C library that has been around for quite a long time), you'd expect it to be fast. I'm impressed that marshaling back and forth across the FFI boundary isn't causing more slowness, but perhaps it is, and the real issue is that rust's regex engine is ju…

> and the real issue is that rust's regex engine is just painfully slow.

The benchmarks game suggests that it's quite fast: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: How come PHP seems so much faster than Rust?

#76

Earlier quoted context omitted.

What's silly is that somebody asked a legitimate question in good faith with code samples and everything, and you responded with an ad-hominem attack with no useful information.

Didn't someone here say we should judge a language by its community? Well the Rust community is not very nice.

OP of the Reddit post here. I made a Hacker News account just to come here and reply to you, because I would like to set the record straight in this regard.

I have always consistently found the Rust community to be nothing but amazingly helpful and friendly. I've posted in the Rust subreddit before in a different account and got the same helpful and friendly responses I did this time.

If we should judge a language by its community, then I, for one, wholeheartedly recommend Rust.

There was actually another post recently where someone asked a similar question only about Kotlin, and there ended up being this collaborative effort where people kept rewriting and optimizing both his Kotlin and his Rust code. Check it out:

https://www.reddit.com/r/rust/comments/d85gyh/why_is_this_sl...

There's an update too:

https://www.reddit.com/r/rust/comments/d8kew3/why_is_this_sl...

Re: How come PHP seems so much faster than Rust?

#77
post #33

Earlier quoted context omitted.

>for a long while [PHP] was the only viable language for developing web applications. That is not what I remember. CGI existed before PHP (1994), and was used extensively for web apps (ebay still appears to use it to this day). Also, mod_perl and Java Servlets were introduced around the same time, circa 1996, so I don't think it's correct to say PHP had a monopoly on web apps "for a long while".

The friction involved in getting those other technologies up and running was not trivial though. That played a role in php's initial success, because it was trivial to get up and running.

>The friction involved in getting those other technologies up and running was not trivial though.

That is only in relative terms in its time. For the past few years I keep thinking how the hell did Web Development went from Perl and CGI, arguably troublesome but understandable, to PHP which is ugly but easy to set up and running, to present days of... depending on which timeline you are, vagrant, VM, docker, k8s, Node.js... I would argue even Heroku with Ruby Rails isn't anywhere as easy as they were than the old days.

Re: How come PHP seems so much faster than Rust?

#78
post #77
post #33

Earlier quoted context omitted.

The friction involved in getting those other technologies up and running was not trivial though. That played a role in php's initial success, because it was trivial to get up and running.

>The friction involved in getting those other technologies up and running was not trivial though. That is only in relative terms in its time. For the past few years I keep thinking how the hell did Web Development went from Perl and CGI, arguably troublesome but understandable, to PHP which is ugly but easy to set up and running, to present days of... depending on which timeline you are, vagrant, VM, docker, k8s, Nod…

Indeed. I am much happier developing with Ruby on Rails than I was with say, PHP, but I do find it hilarious how back in the day deployment just meant uploading a couple of PHP files to a server and how now I need a full CI pipeline.

Re: How come PHP seems so much faster than Rust?

#80
post #37

Earlier quoted context omitted.

While your observation is true to some degree, I do remember ASP, Cold fusion, CGI and a few other more obscure technologies way back when. Perhaps I was quite late to the party though - I only started programming in 1999 (got a computer for my 11th birthday!) - so I'm not sure what it was like before then.

ASP and ColdFusion both required license fees at the time I believe (asp the Windows server license and CF of course the CF license) CGI just would run any type of script. Originally that was typically Perl but PHP surpassed Perl for a variety of reasons. PHP could be run either through CGI or through mod_php in Apache. There was also a mod_perl I believe and a few others but php is what web hosts typically installed…

Why did php beat perl?
Post reply on HN