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".
Coldfusion was also a thing around that time. Flash sites as well.
How come PHP seems so much faster than Rust?
61–70 of 116 posts
Re: How come PHP seems so much faster than Rust?
#62The top reply says "Don't underestimate PHP when regexes are involved." and linked a benchmark [1]. But in that benchmark apparently Rust is faster than PHP (The slowest "Rust #2" is 2.45 sec. while PHP is 2.80 sec. He also mentioned "PCRE", but the ones with Perl in name are even much more slower [the fastest being 14.95 sec.]). Did I miss his point by linking that benchmark, or did I interpret the benchmark wrong?…
fyi "Regular Expressions (Perl-Compatible)"
Re: How come PHP seems so much faster than Rust?
#63Random guess: There will be some difference in the regex engine speed, because PCRE is very fast in common cases. But doing a single regex match is not that much work, so it probably boils down to I/O. And PHP might use extra buffering to get better throughput for the common "stream a file" scenario. Similar question with Python being faster than C++: https://stackoverflow.com/questions/9371238/why-is-reading-l...
The program source code is shown.
Re: How come PHP seems so much faster than Rust?
#64Reference: https://www.reddit.com/r/rust/comments/5zit0e/regex_captures... 2 years ago, but it's still valid to me, I've just tested it and it's much slower as I expected. Feel free to correct me if I'm wrong :)
Re: How come PHP seems so much faster than Rust?
#65While 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.
PHP only became viable with version 3, around 1998, and having most ISP only offering a choice between CGI (usually C or Perl) and PHP, naturally drove most cost oriented devs to PHPs.
Those willing to shell out more, could use one of the above options.
Re: How come PHP seems so much faster than Rust?
#66Earlier 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.
> 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?
#67While 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)!
I could probably compete with python if I used guile's lower level C-procedures, but I sort of lost interest after that :)
Re: How come PHP seems so much faster than Rust?
#68The top reply says "Don't underestimate PHP when regexes are involved." and linked a benchmark [1]. But in that benchmark apparently Rust is faster than PHP (The slowest "Rust #2" is 2.45 sec. while PHP is 2.80 sec. He also mentioned "PCRE", but the ones with Perl in name are even much more slower [the fastest being 14.95 sec.]). Did I miss his point by linking that benchmark, or did I interpret the benchmark wrong?…
> … "PCRE", but the ones with Perl in name… fyi "Regular Expressions (Perl-Compatible)" https://www.php.net/manual/en/book.pcre.php
Re: How come PHP seems so much faster than Rust?
#69Earlier 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 .
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.
- 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 display it back in the HTML form. And if you already "escaped" it for SQL, it will be malformed. And vice-versa. Moreover, any data must be formatted properly before use, not just something that you tagged as "input".
- the word treated above is for a reason. Because the term "escaping" suggests some certain routine in PHP, which is the actual reason for numerous SQL injections.
Re: How come PHP seems so much faster than Rust?
#70This 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…