Live data from Hacker News

How come PHP seems so much faster than Rust?

reddit.com

41–50 of 116 posts

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

#42

Earlier quoted context omitted.

I don't like it from the security perspective, looking at just how many vulnerabilities PHP-based software has had, it's too trivial to create a XSS, SQLi, CSRF, LFI, RCE and many other classes of vulnerabilities. I think there are better options out there than on average give better results. Maybe it's just incredible selection bias I'm encountering \ shrug .

But plenty of those vulnerabilities are not the fault of the language but the frameworks written by others. You can just as easily create SQL injection attacks in a Rust program or Ruby program. You can just as easily introduce XSS/CSRF problems in any of them. Etc.

If the majority of frameworks for a language are vunerable it's the language's fault. Python definitely doesn't have that issue, Rust and Go don't either.

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

#43
post #36
post #31

Earlier quoted context omitted.

Not a monopoly, but it was the easiest and most performant option at lower price points. Java required specialised or dedicated hosting ($$$). CGI was slow as hell. Mod_perl often was not available in shared hosting, for whatever reason. PHP was cheap, fast, ubiquitous, and Good Enough ™, for about a decade. Then VPS happened and the market changed.

Most people initially deployed php via CGI in my experience. I don't remember when mod_php arrived, but we'd been using PHP for quite some time at that point. While CGI was slow-ish, alternatives like fastcgi were already around (and in fact running PHP via fastcgi was also quite common for a while. By the time PHP became ubiquitous, most people had moved away from plain CGI regardless of language.

> in fact running PHP via fastcgi was also quite common for a while.

Mind clarifying how this is different from the current hotness (from what I can tell, due to a decade-old shortcoming that no longer exists in mod_php/Apache MPM options) where folks are running PHP via the Fastcgi Process Manager?

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

#44
post #28

Earlier quoted context omitted.

I don't like it from the security perspective, looking at just how many vulnerabilities PHP-based software has had, it's too trivial to create a XSS, SQLi, CSRF, LFI, RCE and many other classes of vulnerabilities. I think there are better options out there than on average give better results. Maybe it's just incredible selection bias I'm encountering \ shrug .

Your argument is a form of survivorship bias. You're not acknowledging all of the gaping security flaws in contemporary web-development frameworks. People were writing sloppy PHP before CSRF and XSS were even invented. Yet somehow, Python, Ruby and NodeJS have all had numerous CVEs despite those attack vectors being well known at the time a given framework was written. You think SQLi was bad? You should spend some ti…

> People were writing sloppy PHP before CSRF and XSS were even invented.

It is very very easy to write sloppy PHP, definitely easier than in many other languages and default frameworks.

> You're not acknowledging all of the gaping security flaws in contemporary web-development frameworks. P

I'm very aware of them, basically none have (had) as many high-impact vulns as PHP-based stuff does.

> Yet somehow, Python, Ruby and NodeJS have all had numerous CVEs despite those attack vectors being well known at the time a given framework was written.

You're not acknowledging the orders of magnitudes difference between the impact of an usual PHP vuln and those you listed.

> You think SQLi was bad? You should spend some time thinking about the numerous attack vectors available today in nearly every GraphQL implementation

The flaws in others are a very poor excuse for flaws in a thing itself.

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

#45
post #39

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.

Not sure I agree with this. Here's why: new tech stacks crop up every few months, and they're all competing for the same developer brain space. If PHP wasn't easy, I'm certain the interest in it would have evaporated to a large extent. Yet even today, people are choosing to start their projects in PHP. I think it's simplicity has a lot to do with it.

But PHP was essentially the original widely adopted lambda cloud function. 1,000s of dirt cheap shared hosting platforms showed up on the scene. The reason they could make the hosting so cheap was that the way PHP runs. You are only consuming resources when you are serving the request.

To this day, cloud functions still deal with "cold starts", where this was already a solved problem with PHP shared hosting.

All PHP needed to be was good enough. It was how it served pages that made it as popular as it was.

Large disclaimer, I know a PHP shared host was not actually scalable like AWS Lambda. Just the idea that any small business could plop down a few servers and start selling shared PHP hosting was huge back then.

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

#46
post #37

Earlier quoted context omitted.

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.

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 in the early 2000s.

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

#47
post #37

Earlier quoted context omitted.

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.

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.

> I do remember ASP, Cold fusion, CGI

This is the competition that PHP was so much better than.

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

#49

Earlier quoted context omitted.

The reason for picking it is for memory safety as well as performance. If your problem involves a lot of regex and memory safety isn't as critical, then feel free to pick a language with good regular expression libraries. If regular expressions are a smaller part of your problem you're solving, looking at overall performance is better than benchmarks like this.

I'd never know that if this post didn't exist, so I don't think the investigation is silly at all.

Your conclusion is correct, but the reason I take issue is that that’s not the thesis of OP. OP’s original subject/headline suggests that, or questions why, Rust is generally slow vs PHP, and uses a regex example as the “proof”. A person who didn’t read the Reddit comments, or who is less versed in critical thinking, may accept the example as a valid proof of the thesis, instead of simply noting the fact that Rust may not be as good at regex as it is at other things. If the Reddit subject was “Rust is worse than PHP at regex”, nobody would bat an eyelid and the resulting conversational threads would have a different tenor (and your conclusion would and should be the same).

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

#50
post #19

Earlier quoted context omitted.

This is more than a little silly, and simply shows that the self-proclaimed PHP developer (who is "not surprised that PHP is 'fast'") has little to no idea what is costly in execution time, even in such a tiny example of a program, and has no idea how to figure that out.

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.

On the contrary. I provided the most useful information there is (_T_I_N_Y_), even if I didn't hold your hand, either (although I wasn't really answering anyone's question, but rather commenting on it).

But we can't all be geniuses. I'm not one, either, but I don't feel attacked by anyone for pointing that out, and you shouldn't, either.

Post reply on HN