New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Comments
Nothing.
No, seriously, nothing. It's not a good language because so much of it has grown organically rather than being designed, it doesn't have sensible dependency management nor a proper module system, it's not particularly fast, anything long-running is a pain to do with it. Many of these issues are inherent to the language's design, and can never really be fixed.
The only "benefit" of PHP is that you can drop PHP files onto a server and have it work, which is a) not even always true (when you need custom routing with rewrite rules, when you use Composer, etc.), and b) actually a big security tradeoff; because the user is allowed to execute any path of their choice (this is how the CGI model works), things like shells are possible.
Having worked extensively with both PHP and JS (also using Node.js), I genuinely can't think of a single reason to pick PHP that isn't based on some really bad tradeoff.
I mean, obviously it will take some time to learn to work with JS if PHP is what you're familiar with, so for you specifically it may not be worth it to immediately start doing everything in JS, because it'll take longer initially. But looking at it from a "not familiar with anything" assumption, the better choice would be JS.
https://thinkmobiles.com/blog/php-vs-nodejs/
PHP is simple, easy to learn and mature in web development area. Haters gonna hate.
PHP has far more syntactic rules and weird edge cases than JS does. It's not "simple, easy to learn" at all - it just seems that way, because it typically doesn't tell you when you're doing something wrong. Which means that in the end, you end up wasting far more time trying to figure that out for yourself.
Built on an inherently flawed foundation, largely unfixable, and due to its design stuck in an execution model that hasn't been able to effectively keep up with modern requirements (eg. semi-realtime long-running things like websockets or SSE). It's 'mature', sure, but that doesn't mean much when the fundamental design isn't up to scratch.
There's a big difference between "hating" and "criticizing". This is the latter. PHP just isn't a good technology.
That article is so full of nonsense, I'm not even sure where to start.
And yet PHP have unimaginable more adoption than nodejs. Yea, it's older, but still. I do not defend PHP, just saying, PHP is better and time proven choice for web development. Specially from business perspective, because it's easy to find PHP dev.
Nothing is perfect, everywhere is tradeoffs.
The latest php versions aren't that bad. Just make sure you're not using PHP5
I guess I should elaborate a bit on the 'full of nonsense' point. Here are some random examples:
Node.js isn't a language, it's a runtime for JS, in the same way that "the PHP interpreter" is a runtime for the language PHP. That means it doesn't have "an almost identical syntax to JavaScript", you literally are writing JavaScript.
This makes no sense. What database you use has nothing to do with the language you use. It's a totally separate thing that'll work equally well regardless of language.
What? It doesn't have "multithreading" in the way that most people would understand it. Recently something called "worker threads" has been added (which isn't regular multithreading either), but I think they are just referring to the event loop here - which definitely isn't multithreading.
That makes no sense. More code for what? How is "more" even measured? More lines, more characters, more complexity? This sort of thing without explanation is a sure sign that the author doesn't actually know what they're talking about.
CMSes, sure, PHP probably has more of those. But "frameworks"? Leaving aside that it's really ill-defined what a "framework" actually is, and the most common definition (a monolithic framework) isn't actually a desirable thing... there's almost certainly a lot more variety of choice in the JS ecosystem. Not that you'd actually want to use monolithic frameworks, though.
No, modules are not "downloaded" when called for the first time. They are separately installed through a package manager, as a step prior to actually running the application. The same is true for PHP, too, though it'll be includes there rather than modules.
"MEAN" isn't a "software package", it's a marketing ploy by MongoDB, a 'stack'. One you'll want to avoid, by the way.
The cluster module does almost nothing, and while it can be useful, it isn't some sort of magical expansion capability that PHP is lacking. By this metric, PHP also has 'expansion capabilities' because you can run multiple PHP processes.
There are probably many many more issues in that article, this is just a selection of what's wrong with it...
And? The question was about quality, not about popularity.
That's literally "defending PHP".
Technically correct, but also a terrible excuse for justifying using something that has worse tradeoffs than other options, as is the case with PHP.
There's this widespread belief that all technology is equal, that all technology must be a good choice for something, but that simply isn't true. Sometimes, certain options are just badly designed and are never the best solution. JWTs and MongoDB are two other examples that come to mind.
@joepie91 is definitely an expert in Node.js. Hope that I have projects that are significant enough to ask for code review one day.
Can I ask what is the most common problems or mistakes in all the Node.js code that you have seen so far?
I'd say, in no particular order, off the top of my head:
Anything with dot something is a big turn off for me. Perhaps asp.net is the cause.
Wonder what next month's "favourite" will be..
Look at the proliferation (and bloat) of so-called apps and ask what will be relevant in five year's time. Composer, ansible, node.js, pear, javascript, PHP, COBOL - an almost infinite list.
bah, humbug!
there are many reasons
the most important is being light weight
best example of PHP coding imo is wordpress, which works fine and is used by a very large number of websites
if you plan on working on big projects, yes, node is better suited for that
of course we can argue all night long with pros and cons, but here i'm talking about numbers, php is still used in many places, it all depends on the situation, same thing with mongo and mysql
Wordpress still uses MD5 for password hashing (yes, really), still uses unsigned automatic updates (which means you can instantly hack every WP install in the world by compromising the update server), and its plugin system is badly designed, resulting in a lot of plugin security issues and conflicts, on top of just plain messy code.
Really probably not the best example if you want to sing the virtues of PHP...
"Talking about numbers" is the problem. Numbers aren't what matters.
It really doesn't, though. Both PHP and MongoDB are just plain bad options. I'd love to hear of an actual real-world usecase where, all things considered, PHP would be a better option than Node.js, or MongoDB would be a better option than PostgreSQL (not counting MySQL here, due to some stupidities in its design and UX).
To be clear: I'm not saying that either Node.js or PostgreSQL are perfect, or always the right solution. I'm just saying that there are no usecases where PHP or MongoDB are a better one. For all of the cases where JS and PostgreSQL would be bad options, so would PHP and MongoDB.
PHP is qualified enough to be used by Facebook, Wikipedia, Wordpress, Baidu etc. Those giants done their homework and chose PHP over any other existed alternative. This could tell that PHP is good and in terms of quality is acceptable worldwide.
I'am not qualified enough to really defend PHP, but I wise enough to not bash one programming language over another. There is old niggerian tell: "Don't spit in the well, because later you may drink from it".
What the hell are you talking about? If options are so badly designed, they won't survive a test of time. Users just didn't use them at all.
Personally I was Ruby fanatic until I encountered it in working, corporative environment. Never again I will be so sure that X is better than Y. I wish you the same insight.
node die hard alert
My main problem with php is, it takes too much resource and too many times doing the same thing.
I am having a rest api that upload users response (40 ish insert rows) / users into mysql database. The servers can't keep with the request. Most of the time, it's 503 / 504 timeout.
I literally translated the function into nodejs like by line. and the results is unbelievable. It's so much faster, and using so much less resources. Probably because it's asynchronous.
Also because node.js is not so common compared to PHP, statistically speaking it's less likely to get virus on it.
My main concern about PHP is its limitation when used by a lot of concurrent users, all active doing some sort shenanigans reading and writing into database. I don't think it's about my query. Because I literally use the same query. Is there a way to make PHP lighter and faster interacting with mysql? Because as of right now, node js blowing php out of the water in my experience.
I would say the magic is in the event loop. You dont need to create multiple threads or processes for multiple requests. I know there are ways to configure PHP to not spawn processes / threads for every request but I am not a PHP expert.
About your point on "virus", poorly designed code will always have issues. The serious ones I have seen is parsing POST data as object without doing type checking and directly assign into a ORM query. Eventually you can do a certain level of SQL injection even when ORM is used.
Congrats, you found the right tool for your task. It does not mean that PHP is not good.
You don't know exactly what their rationale has been, and so there's absolutely zero guarantee that their choice is even relevant to your situation. For all you know, it could simply be a matter of "we started with this because it's popular, and it's too expensive to change now".
I'm not "bashing" PHP. I'm criticizing it and making a value judgment. This would be bashing if I were making vague unverifiable allegations, but I'm not. And yes, criticizing a bad tool is absolutely an appropriate (and necessary) thing to do.
Your arguing in this thread shows precisely why people will use something that's badly designed - because "well, everyone else uses it, so it can't be that bad". You only need a handful of not-particularly-competent people to take a liking to something because it "looks easy", to kickstart a hype.
Hell, in the case of MongoDB this was even explicitly exploited to popularize it. The reality is that most people just don't pick their tools based on a full technical analysis, and so technical quality isn't why tools become popular.
Cases where X is strictly better than Y are rare, but they do exist. I am well aware that in most cases this isn't the case. But we're not talking about "most cases"; we're talking about a specific case, namely PHP, and like I said - I'd love to hear about a usecase where PHP is genuinely a better option than Node.js, surviving a technical analysis.
I've asked many people to give me such a usecase over the past several years. Nobody's ever managed to come up with one. I wonder why.
This specific issue probably happens because you're creating a new connection for each handled request in PHP, whereas in Node.js you'd almost always be using a connection pool - which you can do for anything, because you have a long-running process.
This is pretty much irrelevant. Whether you get hacked or not, has more to do with the code you write yourself, and how well the tools you use try to keep you from messing it up.
I believe you can set up connection pooling for MySQL specifically in PHP as well. Give that a shot.
I insert 76000+ row every 5 minutes, execute time less than 1 second.
(Mass insert)
I think you run insert on foreach.
Nodejs execute insert in worker threads, php execute on single thread.
I don't recommend NodeJS for monolit project, hard maintainability and i worrying from the memory.
(Try update a popular framework / library three years ago version to latest version. Laravel 5.5 => 6.0 not to hard.)
I think look .net core
The thing is, when googling connection pooling mysql php, most of the resource says, you can't. At least not on how node js works. In node js I can query 10 statements at the same times with one request, and return when promises fulfilled. I can't do this in PHP. In php I need to run the statement one by one.
So in my use case it is INSERTING 40 rows at once VS INSERTING 1 row 40 times. Unless I am missing something.
OMG did you just say they giants did their homework and chose PHP over any other existed alternative?
You do realize nodejs wasn't even a thing when they started up.
You also realize facebook was created in a college dorm room as pretty much a joke? LOL
From my perspective I like both PHP and Nodejs for different problems. Not every language is the best for solving every problem.
Hence the thread title. What's PHP Excel at.
I agree with @joepie91 re PHP. And NO, PHP will never have a version with a properly designed and implemented language. Simple reason: That language wouldn't be PHP anymore. All they can do is to take care of the worst problems and to make it a bit less painfully slow.
That said, all weakly (or not) typed interpreted languages are more or less sh_tty in terms of safety and security - but they are comfortable and ideal choices for hobbyists and quick and dirty jobs.
As for javascript and in particular nodejs things aren't all rosy either but at least there are (a) better languages that compile to javascript and there are (halfway) typed dialects.
TL;DR Anything - incl. even Brainf_ck I guess - is better than PHP.
Any kind of synchronous processing that needs to be scaled linearly - image processing etc.
PHP guys made one very good decision, i.e to have a shared nothing architecture. (NodeJS is more like shared everything and you must be very courageous to run any long running NodeJS process without Forever, docker or PM2)
from PHP 7.4 you get strong typed properties, arguments and return types (you get this by compiling Typescript to JS too, though you have to remember, it is more for build time enforcement and doesn't do any run time checks and hence don't use it as a safety net)
For websockets or messaging, I would definitely recommend NodeJS.
for DB related projects, nothing better than c# with its Linq feature.
If you have millions of dollars and can hire expensive devs, go for Java/SpringBoot, you cannot go wrong with it. Literally every big app is written with it, Kafka, elasticSearch etc etc etc.
In terms of the language itself, PHP doesn't excel at anything. The thing that PHP really excels at is the ecosystem that has already been built and continuously consolidated around it: all the codes, projects, templates, frameworks, guides, docs...and most importantly, the number of users and developers that are familiar with it. Language-wise, NodeJS is better than PHP, but if I have to make a forum or a blog, I'll obviously use a mature PHP script like phpBB or wordpress, because there's a lot of resources that are readily available for for me to quickly get it done, instead of having to code for days or months myself.
You can say asm language is better than all other languages, but it's just not feasible to code a website with ASM/BF. I once made a web page using BF showing a single sentence "HAPPY NEW YEAR!", and the code is as long as f_ck LOL
EDIT: link to that BF code https://pastebin.com/im3830yY
I think PHP gets a lot of undeserved flack because it's popular with beginners that write trash code. The reason why Wikipedia, Facebook etc use PHP is probably because they started off small with not a lot of requirements. Especially back then, getting started with PHP was super easy compared to the other options out there.
Now that I am working on a fairly large project myself (200k+ lines of PHP), I am running into a few issues that make it painfully apparent that PHP was never meant to be used for large scale applications, which is one of the reason why Facebook created the HHVM project in the first place. Unfortunately that never really went anywhere, with a lot of 3rd party software initially supporting it, but now dropping support.
Think of the lack of threading support, enums, structs, polymorphism, horrible garbage collection (because it was designed to clear all memory after a request is done anyway) making creating long-running daemon scripts with it nearly impossible, generics despite claiming to be OOP etc etc. In retrospect, I would have definitely chosen a more mature platform.
They don't (anymore). They use "Hack" which is kind of an enhanced and safer PHP.
As for "small and hobby projects" vs. large/professional projects I agree.
PHP is a lot easier to learn than JS. Maybe browser-side JS is easier - though to do anything significant you're typically learning more about the big packages/libraries than core JS itself. But server-side, NodeJS is an enormous paradigm shift to those coming from a background in perl, python, C/C++/C# or really any other language.
PHP is actually pretty easy to learn. That said, it's a ghetto of crap slapped together. If I am scripting, I vastly prefer perl (mainly because I've been writing it since Perl 3) or Python (which is more elegant but also more verbose). But you can write "good" php...it's just kind of sad.
I would wager that if you took either a completely novice programmer or someone who has some experience, gave them a program to write in both PHP and NodeJS, and timed them, PHP would win. I came to PHP from decades in other languages and it was trivial to pick up. NodeJS was far more challenging because of the mental gymnastics of its different model.
What does PHP excel at? Ease of google answers if you're writing web-only code. I think that's the answer...if you're doing something in php, odds are very high that you can google a snippet to copy/paste.
COBOL still has a massive presence...far, far more than PHP. A 2017 study estimated 220 billion lines of COBOL still in production use every single day. However, no one would argue the merits of COBOL over more modern language. Numbers mean nothing. No one is arguing that there's isn't a lot of PHP. It's easy to find a shared web host to drop your code on. Doesn't make it better.
And Mongo? There is never a valid reason to choose Mongo. Other NoSQL systems perhaps but Mongo is a pariah.
To add, definitely check out https://deno.land/ - looks pretty promising.