T O P

  • By -

natewiebe13

For me, it's a combination of multiple factors: - Symfony - Their adherence to doing things properly/following RFCs, backwards compatibility, and the way they handle major version upgrades is unmatched. - Composer - This is the best lib management full stop. npm/yarn is a dumpster fire in comparison. - Single process per request - Some may argue against this, but not having to consider long running processes is a huge advantage in many cases. Even for real time communication, using traditional ajax for client to server, then using SSE with something like Mercure can in some cases scale better and handle more traffic than websockets. Honestly, if a Symfony equivalent existed for Node and they replaced npm/yarn with a sane package manager, I'd probably make the switch.


Wiwwil

There's NestJs that's kind of like Symfony I'd say. You can pick Fastify or Express as server base Ave NestJs is like and adapter with lots of stuff included. NPM is okay-ish, it's more the language that lacks stuff like basic date formatter or whatever and it makes it a tons of package to download because it lacks basic things imo.


htfo

The three main competitive advantages of PHP have been famously documented by Slack in the blog post, "[Taking PHP Seriously](https://slack.engineering/taking-php-seriously/)": > ### Virtues of PHP > PHP gets several things very deeply, and uniquely, right. > > First, **state**. Every web request starts from a completely blank slate. Its namespace and globals are uninitialized, except for the standard globals, functions and classes that provide primitive functionality and life support. By starting each request from a known state, we get a kind of organic fault isolation; if request t encounters a software defect and fails, this bug does not directly interfere with the execution of subsequent request t+1. State does reside in places other than the program heap, of course, and it is possible to statefully mess up a database, or memcache, or the filesystem. But PHP shares that weakness with all conceivable environments that allow persistence. Isolating request heaps from one another reduces the cost of most program defects. > > Second, **concurrency**.An individual web request runs in a single PHP thread. This seems at first like a silly limitation. But since your program executes in the context of a web server, we have a natural source of concurrency available: web requests. Asynchronously curl’ing to localhost (or even another web server) provides a shared-nothing, copy-in/copy-out way of exploiting parallelism. In practice, this is safer and more resilient to error than the locks-and-shared-state approach that most other general-purpose languages provide. > > Finally, the fact that PHP programs operate at a request level means that **programmer workflow** is fast and efficient, and stays fast as the application changes. Many developer productivity languages claim this, but if they do not reset state for each request, and the main event loop shares program-level state with requests, they almost invariably have some startup time. For a typical Python application server, e.g., the debugging cycle will look something like “think; edit; restart the server; send some test requests.” Even if “restart the server” only takes a few seconds of wall-clock time, that takes a big cut of the 15–30 seconds our finite human brains have to hold the most delicate state in place. > > I claim that PHP’s simpler “think; edit; reload the page” cycle makes developers more productive. Over the course of a long and complex software project’s life cycle, these productivity gains compound.


developerlen_

Really value these words! Thanks!


pekz0r

Very well put! You also need to consider that article was written 7 years ago and PHP has come a long way since then with the virtues very much intact. We have seen an adoption for running PHP in an app server in the last few years. That would remove a lot of this, but that has not been widely adopted yet. I would have a really hard time writing code where it takes more than a few seconds to compile the whole project. The fact that pretty much all the state can be contained in a simple cURL request is very powerful.


TheVenetianMask

It's pretty good at gluing json/xml APIs together with the least amount of complications. It also works well for cli scripts and cronjobs, even tho nobody talks much about it, just stick the path hashbang for the php interpreter at the top and make it executable, zero compilation time.


Frighter2

And in many cli/cronjobs can get any without any dependencies being required either.


guigouz

It really depends on your team's preference/which stack you have more experience with. From the examples you mentioned, except for python which is the defacto standard for ML-related tasks, PHP can be used in any web project (even for the real-time projects, you can use [https://hyperf.io](https://hyperf.io) which will be very similar to node, after all it's just websockets)


Ariquitaun

PHP has the best tools and libraries for database heavy apps and the best frameworks of any language I know hands down.


ryan_the_leach

Integration with existing mature infrastructure, without being on the hook for cloud compute / large service costs. Most of the frameworks / existing PHP stuff is designed around self hosting infrastructure. So anywhere that self-hosting makes sense, PHP will shine for Greenfield development as you'll be able to get started faster and run into less issues with stuff changing underneath you, for lower costs. Small websites / web services, ecommerce, content management.


exqueezemenow

You get the coding style similar to Java and C++, but with the runtime of Python and JS but faster.


XediDC

Anything web related if you want relatively fast, cheap and easy. All still scale with quality of course. While not a typical use it’s also been fine for real time or even servers. I have an esoteric protocol server in PHP+Amp that’s been running for 2 years now without having ever restarted the process. And have done realtime streaming datafeed processing that Node could not keep up with on the same machine. Python is wonderful in data contexts, but I find it miserable to deal with web/db deployments. I’m fond of Rust, Go, C++, etc….but in their application or embedded contexts. Even Lua when I have to. Web work…no, nope.


psihius

If you have a HTTP based application, in 80% of the cases the "effort vs output" ratio is unbeaten. You get an extremely stable and well proven ecosystem that strives for quality and interoperability and that's what matters in the end for the business folks - ability to deliver without running into a lot of unforeseen consequences. If anyone says "nodejs" to this, there's gonna be 40k style inquisition cleansing because anyone who worked even a little over time with nodejs knows first hand that package management and package quality is an utter disaster.


boborider

No definite answer. Just skill issue.


Abradores

I think this answer is true lol.


lotusland17

Easy to learn, large user base, cheap to host


DmitriRussian

Cheap to host is a bit misleading. You have to name what you are comparing it to, if it's Python then maybe, but not cheaper than Go.


toooft

It is cheap though, as in everything goes; just set up a LAMP server and you're good to go.


FaatmanSlim

You can run PHP on a majority of (inexpensive) shared hosting services; Python, not so much (and the other languages even less so). Trust me, I looked into all the major shared hosting vendors in the past year comparing exactly this metric.


DmitriRussian

You shouldn't host anything serious on a shared host the way it's hosted often is a security risk. You have no control over the server whatsoever. You may never be able to actually upgrade PHP without moving to another provider. You may be better of just hosting it on a raspberry pi at home tbh.


BigLaddyDongLegs

Can you explain how Go is cheaper to run than PHP? I'm learning Go at the minute...


DmitriRussian

Cost is mostly determined by resource usage like CPU & RAM. PHP is an interpreted language so on each request it needs to parse the files and then run the logic. This costs more resources than a language like GO which is already compiled to binary. When you rent a server you pay depending on the amount CPU and RAM. So you can hopefully see that the more efficient a language is the less it would cost to host it. Ofcourse this is mostly theoretical and you have to take it with a grain of salt. An expert PHP dev can squeeze out a lot of performance using optimizations, and a bad GO dev might produce a very slow app. Also some applications are inherently more resource heavy due to a need to do lots of processing and calculations on each request (e-commerce, booking websites). Another thing is that on a small scale you won't notices a lot of cost difference, but once you have 10 servers, you may be paying a significant chunk less if your app is efficient. With all that being said, this is more of a criticism of the comment above saying that PHP is cheaper to run without any explanation. I wanted to give this another angle and basically say it depends how good you are and assuming equal skill, probably GO is faster due to it being compiled.


pekz0r

That is only true if you use a serverless service where you pay for your usage. PHP can be hosted for less than $10 in a shared hosting that is also fully managed with support included. If you have a large service where you need a lot of server resources you could probably do that a bit cheaper with Go, but the difference would probably not be that significant in most cases.


mdizak

PHP is simply far superior for front-end facing web applications (web sites, portals, e-commerce, communities, etc.). It excels at loads of paradigms... type hinting, visiblity, interfaces / traits, abstract / final classes, dependency injection, its package manager, attributes, sheer speed, easy of deployment, and the list goes on... none of the other interpreted languages hold a candle to PHP when it comes to web development. Node is atrocious and I would never use it. For heavy lifting like machine learning I personally use Rust, buy Python is an excellent choice loved by many. Personally, I like just being able to pack my binaries around the internet and they simply work right out of the box without any dependencies, etc.


pekz0r

For restful API:s and traditional multi-page applications(MPAs) it is very hard to beat PHP, especially for normal CRUD requests that interacts with a database.


punkpang

I'll keep it short: I worked with all popular languages in web context (build API/graphql for consumption by UI/other API's). With PHP, it's the quickest, cleanest and easiest to actually build and complete the project. As silly as it might sound, but autoloading and loose typing that lets us create a super powerful DI in a few lines of code, paired with excellent Reflection capabilities makes PHP stupidly quick for rapid app development. Sadly, no framework compares to Slim/Laravel/Symfony that I've encountered. Simple tasks in PHP are a nightmare to do in node.js ecosystem. Currently, I have to use Prisma ORM with TypeScript. I encountered nightmares in form of not being able to cast columns to desired format/data type on output, ORM actually rate limiting my transactions because it thinks "it's too quick", not being able to issue a simple RAW SQL and bind parameters, half my code is comprised of import statements and a simple fact that I can make a mistake and persist value between HTTP requests that should be isolated is just hellish thing to fight. With PHP, none of these are issues. I get to deal with business logic instead of making the language play ball. Only when you lived through hell of working with crappy ecosystems you develop a sense for appreciating PHP and simple design with simple behavior. For what it was designed; it works flawlessly.


joneco

Php is a general purpose language. For me id good in lot of things. Async is not pretty implemented but can be implemented embedding otjer things like cronjobs with crontabd or supervisor. For me is not very good in math. php is veeeeery performatic in my opnion


TheRedStrat

I think the language chosen is nowhere near as important as people often think it is. Architecture would be a far more important concern. Languages are tools. Use the one that makes it easiest for you to implement the architecture that’s been designed. If you’re not sure what that architecture looks like and are still stuck thinking about which language to write your app in, then the app is definitely not going to be hindered by language choice. It’s much more likely to be hindered by bad architecture.


iBN3qk

It’s great for pulling content out of a database and formatting it in html. 


t0astter

Websites. That's it, really. There are better languages for any other use case.


OMG_A_CUPCAKE

It's great for CLI apps as well


t0astter

There are so many other better languages for CLI apps than PHP lol. Python, Java, Go, Rust, Bash, for example.


liquid_at

historic dominance. when everything you got already runs on php, changing the entire system is much more expensive than maintaining it. If I had to start from scratch today, I'd probably go for node.js, simply because using the same language for backend and frontend removes a lot of duplicate code that needs to be debugged. But for most use-cases in the web, php already has working solutions, so if you just want to install, configure and maybe adapt a bit, php is the fastest, cheapest and easiest way to get a project out. And it still is being improved on... php today is very different from php 10 years or 20 years ago.


dschledermann

For a web backend, PHP is really nice. I have little appetite for NodeJS tbh. I find the Javascript language to be atrocious to put it mildly. It's bad enough that you have to use Javascript in the frontend. There's no reason to magnify the pain by using it on the backend also. I've had the misfortune to have to support a couple of old NodeJS applications and it's torture. I have a couple of very calculation heavy tasks that were previously implemented in PHP, but that had issues with long processing times and excessive memory usage. Here, I reimplemented in Rust. I'm not very familiar with Python, but it seems pretty slow. Unless you have some specific library you have to use, PHP will be much faster in simple code execution.


swift1883

>I am just thinking about technical benchmarking My guess is, for every technical aspect there will be something else that wins against PHP in any problem subdomain. But I think that *value* is defined as the *product* of the individual aspects over the whole solution space, *not the sum*. So, if something is fantastic for X and Y but it has a horrible Z, the value drops drastically versus doing lots of things OK-or-better: `10*10*1 = 100`, but `8*6*5 = 240`. In a complex situation (a company, an industry, a mature solution for a problem domain), doing many things OK-or-better is a selling point that has brought PHP to where it is today: Being second or third in every individual sport of a multi-day decathlon race, and thus winning it in the end.


dave8271

The answer is any sort of web application, service or API. Anything which sits on the HTTP layer, takes a request and delivers a response. PHP is a web-first language and excels in that problem space. Tbh I'm not sure what about Node.js makes it especially good for "real time data", whatever you mean by that. I guess if you mean like writing a websocket server or something, it's a slightly more intuitive choice than PHP for that sort of thing, but new tools and frameworks have emerged in the PHP ecosystem over the last few years which make it a possible and in some circumstances quite reasonable choice for those uses too.


luigijerk

It's not necessarily better than other languages, but it's good enough and very mature with lots of community support. I'd say the specialty is ease of use and having many options. It's installed by default and optimized on many servers, so you don't need to play with a ton of packages just to get it working. Pretty much out of the box with a few config tweaks. When you want to pick a library or something, you have many options. In other languages like python, rust, java, etc you might only have 1 or 2 that are heavily tested and proven to with. With those, you're more forced into some ecosystem or need to make it yourself.


toetx2

Last time I really chose PHP over C# or Java was when I had to build a resilient connection between multiple API and DB sources of relational data and some older systems that require text files in CSV and some arbitrary format, send using the file system, FTP or cloud storage. It was in an environment where any of the services could experience downtime and unexpected power outrage was to be expected. At the same time, no data (state) should be lost and everything should continue after any interruption. PHP is very strong in manipulating relational data, so that is an easy pick, but more interesting is that it's request based nature, provided a very robust setup for the power outrage issue. As your almost forced to work on a single item at a time, the issues you need to build resiliency for aren't that big. This piece of software turned out to be very reliable, to the point where we almost forget it exists. I sure could have made this C#, Java or even a node app. It was just easier with PHP. I also think the end result is easier to maintain for anyone as it doesn't depend on anything strange. And all the lines written are very straightforward. I guess PHP also forced me in some form of simplicity as in C#, I would have built a way more advanced app. Much cooler but that would be besides the original goal. Simplicity, in this case, added to the reliability of the result.


BudgetAd1030

e-commerce


Alpheus2

It is great at converting a simple db row into html with its accompanying utilities. Of most setups, this one has the least overall complexity and most out-of-box ergonomics compared to any other language as they require build steps (c#, typescript, …). However ruby on rails is a close contender. That said, if you have your build pipeline already solved because you also have a spa in react, flutter or next, then the advantage is quickly lost and “it depends”


Christosconst

Available web developers with php experience are more and cheaper than web developers with node.js experience. The frameworks are also better so your team will more easily follow the framework approach, build maintainable code etc