phpc.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A server for PHP programmers & friends. Join us for discussions on the PHP programming language, frameworks, packages, tools, open source, tech, life, and more.

Administered by:

Server stats:

792
active users

can someone convince me why #php is good actually

@Crell a little bit of both, but mostly genuine. i keep seeing frameworks like laravel pop up in web development and we use it at work in some of our microservices so i'm interested in knowing why it's attractive as a language/how performant it is compared to something like rails

@taco In it's niche (server side web), PHP has an incredibly robust ecosystem, the strongest type system of any interpreted language, the best or second best package manager (competing with Cargo), and is either the fastest or second fastest interpreted language depending on what you're testing. (JS is the competition there.) It scales horizontally better than any other architecture. And its "it just works" factor is second only to Go. It's also very easy to learn.

@Crell appreciate the explanation! definitely make sense why i see it so much, then.

@taco There is a ton of outdated information about PHP out there. Many of the criticisms of PHP were fixed a decade or two ago, but haters love to hate on PHP for funsies.

Modern PHP is overall a very pleasant language to live in, especially if you're using a good framework. (Obviously bad code is bad in any language, and plentiful.)

@Crell @taco For what it’s worth, Etsy’s backend still runs on PHP, and we’re fairly up to date. It’s not as bad as a lot of people seem to say it is.

My personal biggest gripe is the lack of a language syntax for expressing/enforcing async behavior. Something can become “blocking” (network, database, whatever) unpredictably and cause significant performance problems.

JS has promises, async/await, etc, where you can explicitly encode/enforce/understand that.

@sangster @Crell @taco I'm not completely sure if I understood you but as far as I know even this is in the past now with fibers. php.net/manual/en/language.fib

www.php.netPHP: Fibers - Manual

@doomhammerchen @Crell @taco well, it’s better than nothing, but I’m honestly not sure how I would go about actually using that in our codebase. I guess I’ll ask some smarter PHP people than myself. It still seems like the do/while waits for the fiber to resolve would be necessary and still lead to surprise “blocking” steps without rewriting our whole stack on top of fibers.

@sangster @Crell @taco I share your opinion. Using fibers directly is a little bit messy. I for my part always used the libraries amPHP (amphp.org/) or reactPHP (reactphp.org/). The later gives you a very JavaScript-like experience. In any case: no surprise blocking

amphp.orgAsynchronous Multitasking PHPAmp is a non-blocking concurrency library for PHP based on Revolt.

@doomhammerchen @Crell @taco oh nice! Our architecture is way too bespoke for introducing something like that, but I’ll go read up for my own edification :)

@sangster @doomhammerchen @taco Fibers were never intended for normal people to use directly. They were added for the express purpose of enabling Revolt to exist. What normal people should be using is Amp, by design.

@Crell @doomhammerchen @taco ah, good to know. Well, I’ll bug Rasmus about it when I’m back from vacation and see if he’s been thinking about how to integrate it into our systems.

@taco The downside is that because it's so easy for new devs to use, there's millions of lines of... Really bad PHP out there, often in mission critical systems. The 2 biggest app/frameworks, WordPress and Laravel, are canonical examples of what not to do. (There are better options.)

Lots of 3rd party tutorials are very out of date and bad. If you stick to the official/main channels you should be fine.

Were it up to me, the only server side langs I'd consider are PHP, Go, and Rust.

@Crell @taco php got me started developing and now I've made a whole career of it.

PHP was really bad in the 5/6 days. 7+ really added some good language cleanup, but a lot of people were already using subsets/sueprsets like Hack and Hiphop.

I haven't really touched it in years (I last had a PHP job back int he Pear days, long before Larvel .. or even Webpack, Vite, all that other frontend garbage).

I heard it's gotten better, but I suspect it's in the same camp performance wise as Ruby/Python for web applications.

@djsumdog @taco The last benchmarks I saw show PHP as quite a bit faster than either ruby or python.

@Crell I’d argue that Wordpress and Laravel, both being wildly successful and both being, let’s be honest, significant reasons for PHPs continued popularity, are hardly canonical examples of what not to do. I’d argue they’re canonical examples of what PHP is best in class at - providing a fast way to answer a web-based need and just as importantly, convert that time savings into money.

@josh @Crell Larry is saying they use poor coding practices and/or unidiomatic PHP.

@Crell @taco Wow, I didn't know PHP had a "stronger" type system than Haskell!

@barubary @Crell @taco And I didn't know that haskell is an interpreted language.

@barubary @taco Haskell is a compiled language. If you compare major scripting languages (PHP, python, JS, Ruby, Lua), I'd call PHP's the most robust by a wide margin.

(Before someone asks, typescript is a compiled language so separate category.)

@Crell @taco @danrot #Haskell has always been interpreted. (Before 1984 or so people didn't think it was even possible to compile a lazy language, until the LazyML compiler was published.) Hugs is a pure interpreter for Haskell (sadly no longer maintained), but even GHC comes with an interpreter for ad-hoc scripting (ghci, runghc, and ghc -e ...).

@barubary @taco @danrot Huh. TIL. How does it even do that in anything resembling a performant way?

@Crell @taco "it just works" doesn't apply when you have to set up an entire php runtime and harden it. it's ridiculous to compare it to golang which gives you an all-in-one binary. i'd reserve the "it just works" talking point to go, rust, c, and so on.

@a @taco There's nothing "it just works" about C. At all.

And having tried to use PHP, python, and JS, I would argue Composer is the better package management system by an absurdly wide margin.

@Crell @taco what is the argument for "it scales vertically better than any other language"?

@matzipan @taco I said horizontally, not vertically.

Every request being its own process with no shared state means scaling out more processes in one server is trivial, and scaling out multiple servers is equally trivial.

has been doing "serverless" since before it was cool. :-)

@Crell @taco my bad. Still every other language can spawn new processes. So it's hardly a unique advantage.

Scaling out more processes in a single server is not necessarily the plus you seem to think it is. There's a reason why hhvm has proxygen support.

@matzipan @Crell @taco but the startup time of PHP is more than enviable. I'm currently using it under k8s and I can scale up to dozens of pods in a matter of seconds (using a not-lightweight framework like Symfony), while other projects take minutes to go up (I oversee a Nest.JS one, for example, which takes at least 120s to boot).

@alessandrolai @Crell @taco could be. But hard to draw any equivalence without knowing what each does.

@matzipan @Crell @taco in my example, both are queue consumers, but I've seen the same when providing HTTP APIs, you just have to add 5-8 seconds to both for healtchecks to pass. I also heard of pretty worse situations like Java, where you need upwards of 5 minutes to launch a pod, which requires 5-10 times the amount of memory for a single replica...