549 points · by eiiot · 3y ago · 516 comments
Seriously, PHP is the grand father that will drive you to class and you'll never be late, the car will never smell and everything will always just be fine.
It's fast, it's typed (now), it's reliable.
Laravel is pretty darn rock solid. I've used a LOT of frameworks. Most of them fall on their ass in either the documentation or performance scope. Laravel is beasty, reasonably well documented, handles hundreds of thousands of users without a scratch. Plays well with Redis and MariaDB or anything really.
Just ignore the fugly standard library inconsistencies of (old) PHP, every language has their toilet corner...
Oh and it's free. All of it. PHP, Laravel. And its hosting has always been the cheapest. You don't need a particular OS or certain cloud providers.
When I consider the solutions of flask and microservices I've left behind, the many node processes running with pm2, the complexity of .NET solutions... PHP just works, and it's easy to make reliable... And if it's slow, it's because I'm doing dumb stuff, not because of dark corner edge case I happened to be tripping into.
It's single threaded first, queue jobs for anything slower. That simple facts make it so much easier to reason about things, and keeps the fullstack linear, transactional and easy to reason about, 2 years into it.
PHP is not the best language in the world. I prefer Swift and even Go for many reasons, but it's an easy, simple, straightforward language. It's the BMX of the languages.
That's a state of the art WebApp. You old PHP developer!
Though to be fair, devs lose employability when they don't get to use (in their work) technologies that are gaining wide popularity. It's a balance to be struck by the CTO/architect (assuming the devs want or are able to demand that skills development in the first place).
I get that you are arguing from personal experiences, people you met and worked with. But this statement lacks context and nuance.
There are developers who don't like PHP because of outdated reasons and possibly because they are snobs. Sure, that's a red flag.
But there are many who have so many battle scars and war stories with the language and its ecosystem that they decided it's just not worth the pain anymore. Even though PHP has evolved (with regular breaking changes...) and tries its best to put something useful on top of a shaky foundation: The effort required to make PHP work with you, in comparison to other languages, becomes too large and painful. I'm not talking about superficial things here, nor do I have the tendency to overengineer stuff, quite the contrary. I'm talking about writing simple, robust and efficient code.
However I would say there are three very good reasons why you should use or at least consider the language:
- You want to quickly hack together something useful with minimal fuss, AKA its original purpose.
- Buy-in of the OO, code generation, IoC/DI, magic framework stuff that Laravel/Symphony provide.
- You have to.
> But there are many who have so many battle scars and war stories with the language and its ecosystem that they decided it's just not worth the pain anymore.
I could say the same thing about javascript from the early days, through Jquery, and beyond. Should I turn my nose up to modern javascript because of the past 2+ decades I've been working with it? No because they are "outdated reasons" as you say
> The effort required to make PHP work with you, in comparison to other languages, becomes too large and painful. I'm not talking about superficial things here, nor do I have the tendency to overengineer stuff, quite the contrary. I'm talking about writing simple, robust and efficient code.
Do you have an example of this?
The magic in these frameworks is evil, and likely a big part in ruining PHP's reputation. Laravel in particular hides way too much stuff behind magic, and when it goes wrong you find yourself sifting through OOP-obfuscated layers of framework and libraries just to find out how exactly your controller is called.
Those resonate with me reminding menof some of the worst development experiences in my career. Different language, different domain, but I recognize it. The simplicity is alluring, and even enticed me at first. It just doesn't scale for problems that are complicated vs the ones you are shown as marketing. The managers and architects like it because it hides the confusing or non-elegant details from view, but that just makes it hard for the devs to work on it.
This applies to absolutely every language or stack. You switch to Ruby because the grass is greener, and 5 years down the road you feel the same. Then you switch to Kotlin or Erlang or JavaScript and you'll end up hating it anyways if that's how you roll.
I do understand hiring someone who has that tradesman programming ethic and is comfortable with Linux, but that’s more requiring certain positive traits.
On the one end of the scale you've got the PHP Laravel monolith, and on the other you've got the completely serverless bits of JS over lambdas, with 12 different technologies, buckets up the wazoo, to store 300mb worth of data.
Then you're told 'yeah, but this is distributed'! Okay cool, so you save 50ms of latency. Super... How long does your javascript takes to start returning content? Right, much longer. What the hell is even a cold start? How is that a thing in 2023?
PHP is unsexy. And people don't like unsexy. I, on the other hand, I like my vacations uninterrupted.
But yeah, before you jump through the whole ecosystem of JS and require 3 different third party services, only to make a website, that does not work with JS turned off and cannot be build and run any longer 3 month later, due to dependency fup, you are much better off with unsexy PHP.
This also reflects in their salaries.
And how did it manage that? Python forced people to deal with encodings properly and the result was a lot of pain. You're claiming PHP somehow invisibly fixed the numerous problems of the language without anybody noticing? That "fractal of bad design" blog post, everything described in it has been fixed?
If so I want to learn how they did it. That's some heavy duty language evolution work.
I found the (Laravel) community to be more about object-level discussions ("how to do x feature the best way possible") rather than meta-level discussions.
Serious question, what does that argument consist of ?
I personally never liked PHP, so I haven't kept up with how it has developed and I don't expect to start, to be honest. Of course, if you've got an otherwise interesting project that happens to be PHP and want to pay me to help you with it, I'll be professional about it, but there are too many alternatives that appeal to me more than PHP for anything where I have a say.
Depends on the reasons. One good reason for preferring another language is .NET/Java business app developers can earn a lot more here than PHP developers ;)
So PHP was and might still be a shitty language.
And PHP was my first language I'm fine with scripting with it but it was ugly as hell to write big code
Sure, it's perfectly possible to grow numb to those pains and some will even pat themselves on the back, claiming pragmatism over principles, but wow, if you're not used to that level of make-believe in computer languages you'll be paralyzed by disbelief. An endless series of "this can't be true!"
But when a dev says X is objectively bad, that is not a good sign. Languages are tools, not a way of life.
What's that George W Bush line, Fool me once, shame on...shame on you. Fool me—you can't get fooled again. But we're not talking about getting fooled just once, or twice, we're talking about eight times.
No one got “fooled”. The got a useful tool that got better over time.
This just sounds like PHP Stockholm syndrome with extra steps.
Hard disagree. Sorry, I don't have a computer science degree, why does their documentation make that assumption. I find their docs very hard to grok.
PHP.net docs are no-frills no-fuss, straight to the point. Other frameworks are documented very well too, CakePHP comes to mind (at least, when I was using it last in v2 and v3).
I can't say I've read the absolute latest version of their v10 docs, but when I was neck deep in 5.8 I found I had to switch to older versions of the documentation to read up on some of the most basic of Laravel features. eg. What's the syntax of using Form in Blade templates? I had to go back to v4.x docs to read up on it, Blade templating hardly got a mention in v5.x documentation, despite it being critical component in a Laravel application.
If there was a bug in a project and I had management breathing a fire down at me because it's breaking the site / losing sales / stopping monthly reports from going out, I shouldn't need to decode computer science terms, or look through previous versions of documentation to find the solution.
This is why, in my opinion, Laravel documentation sucks hard.
All that being said, my overall experience of working with PHP / Laravel is quite pleasant, probably more so than other technologies I've worked with in recent years. Everything has its issues I suppose.
[1]: https://laravel.com/api/10.x/Illuminate/Database/Eloquent/Mo...
Ah yes, the Ansible approach. I've used it for a decade, and I routinely get lost in its utterly terrible by-example documentation.
They are the golden standard on how not to write documentation.
God, I hate the Ansible docs so much, they are the reason I burned 30% of my Kagi search quota this month.
Guess that is why selling Laravel tutorials seems to be a fruitful business.
I’m sure that plenty of us used PHP in the day, have been doing something else for a while, and see these HN posts from the people that stuck by PHP singing its praises. Let’s not forget that there’s probably been a steady stream of newbies coming through the system the entire time - which makes the language, and by extension Laravel, a prime target for bottom feeding ‘one step ahead of the audience’ “educational” content producing scum.
eg. https://laravel.com/docs/5.8/contracts – talks a lot about how Contracts are powerful additions (like all the other features of Laravel, the docs are good at telling you they're powerful) and the examples show just some barebones code that doesn't really do much without a lot more work. The examples in the documentation seem to be more on the side of being some code snippets that don't convey much context.
Additionally, there's lots of "congratulatory" text in the documentation ("Laravel has a powerful feature called <x>", "in Laravel adding <feature y> is actually really simple", "some developers enjoy using <feature z>". You simply don't see this in PHP.net's docs, it just tells you what the function / feature is, gives you examples that work straight out of the box, lets you know of any pitfalls or differences in PHP versions to watch out for, and there's a whole list of comments contributed by other PHP devs spanning years, that are up/downvoted.
Another example of powerful documentation was that I learnt what MPTT is, and how to implement it effectively, purely from CakePHP docs back in the day (I'm talking v2 here). I can't see how anything as remotely useful would be able to be taught from Laravel docs alone; for someone who doesn't have a computer science degree, there would be a LOT of tabs open, full of rabbit holes that need to be explored. This is not effective documentation in my eyes.
The difference between these sets of documentation is like night and day to me. The Laravel docs needs to stop patting itself on the back, and be more like other software projects' documentation.
Don't get me wrong, I love working with Laravel, it is powerful. My issue is with the documentation, which leaves a lot to be desired.
To note, you'll need strict mode for type hints to be useful. https://www.php.net/manual/en/language.types.declarations.ph...
The fun part is, instead of going for a generic strict mode system we would have expected, PHP went pragmatic: as most application won't be 100% strict typed, you need to declare it file by file, the icing on the cake being that the restriction applies on the caller of the functions, not the function itself.
It makes for complicated situations, where for instance you can make an utility class that is 100% typed and follows strict typing, but if the caller of your class isn't, none of it will matter and types will be fuzzily coerced anyway.
This is not really true — those type hints can be read by static analysis tools, preventing you from many of the issues that would also be caught in strict mode at runtime.
Unfortunately, it’s taking far too long for Laravel to catch up so parts of its API are a black hole for types.
Especially things like request input, which returns a union of string and array as opposed to using a conditional return type.
You end up with assertion soup every time you touch Laravel so over time the project uses less and less of it.
A well-typed framework and set of libraries would be very nice.
In PHP, typing is for function signature documentation.
false.
Utterly false, I don't know where you came up with all of that nonsense. All type hints work as expected, just you can't typehint variables. Only parameters/class properties/return types.
And the `strict mode` is a failed experiment no longer recommended in new code (no side effects but no benefits either).
Unless you’re getting shared hosting, then it’s true for most things now. You don’t need a specific OS or cloud provider for .NET, Java, Go, Rust… etc
> When I consider the solutions of flask and microservices I've left behind, the many node processes running with pm2, the complexity of .NET solutions... PHP just works, and it's easy to make reliable... And if it's slow, it's because I'm doing dumb stuff, not because of dark corner edge case I happened to be tripping into.
.NET isn’t anymore complex than a PHP app. Unless you write many layers of abstractions. And nothing stops you from doing the same thing in PHP.
Most mature programming languages are nice to work with these days though. At least in my opinion. About the only one I dislike is C#, and that is mostly because whenever I need to use C# I need to use it with a combination of libraries (Odata, Entity Framework, Asp.versioning) as an example which simply don’t work together unless you overwrite/extend half of them. Because for most use cases C# is as excellent as all the rest.
But PHP was essentially build for the modern use case of everything being web-based and it’s weird to see the reputation it still has. Then again, django is also an excellent tool for most modern work that doesn’t see the adoption it should. I’m so sick and tired of having to deal with things like umbraco failing at things that have been a fundamental part of django for longer than some of the people reading this post have been alive. :p
But I guess its all those things that keep me well paid. So maybe I shouldn’t be too angry about it.
Obviously Go and PHP are two very different languages but they bring me peace in ways JS never did. Especially when reopening older projects.
Personally, I do like the way the standard library is - almost all cases of where people whine about it being inconsistent, it is a consequence of the PHP standard library and many of its extensions being extremely thin wrappers around libc and C/C++ libraries in general.
That, in turn, makes it often possible to just take straight C library example code, copy it into a PHP file, add a $ in front of all variables, and have it magically work.
(IMHO, it's no surprise that the whiners tend to be younger programmers who have grown up with Java in their university education - us older "neckbeards" are so used to the C world that its conventions are second nature for us)
* head explodes awesome
I know what I'm doing this afternoon!
Thanks to Laravel (along with Livewire and Alpine.js), and an ecosystem of libraries enabled by Composer, PHP is a great choice for web development. I'd not use it for, say, coding machine learning stuff though!
Totally agree about the single thread thinking is enough for most things. It of course depends on what you build. For example, I would use some language that runs on Beam for a chat platform.
How should I interpret this? The language is cool? Can perform cool tricks?
PHP makes simple stuff easy and difficult stuff possible. (But you're not going to win the Tour de France on a BMX bike.)
Nowadays, a lot of other things also do this, but PHP was the first to really "get" this. I understand it's not for everybody, and for certain things, other languages are certainly better. But there's precious little that you can't do with PHP, since it's been around for so long and has been growing with the Web from pretty much the very beginning.
Sorry, could not resist! lol :-D
Would you mind sharing your insights into why one should go with modern PHP+Laravel instead of NodeJS+Express+Typescript? what does the PHP equivalent of pm2 load-balancing look like and how does it compare?
Thanks to JVM you have really good out of the box debugging features including hot code replacement and profiling.
You can use kotlin which is a really really good language in comparison to PHP.
There is no need in my opinion to write real applications with PHP.
But for web, I personally prefer Typescript frontend and backend combos. It's amazing to be able to write everything in one language. I largely tune out the arguments and new flashy frameworks, but I get why people call the JS ecosystem a hellhole. There are a lot of options out there. That being said, when your team is competent and balances functionality with new shiny stuff, it can be a real treat to have access to npm for frontend and backend.
API Platform is really good for scaling CRUD endpoints too (its a Symfony project, or at least tightly Symfony adjacent)
Of course, this is my experience (albeit over many years) however I wanted to just throw out a worthy alternative people really should look at.
IME, Laravel's "easy deployment" story is heavily linked to the paid service Forge, and installing dependencies during deployment is a bit slow plus takes a /lot/ of memory (we're using old Composer and Laravel versions though). What's your take?
Thanks in advance!
It's quite brilliant really, even for modals etc. "look ma, no javascript!". Of course it does JS for you, you just don't see it. That's my favourite kind of Javascript - someone else's problem. Livewire is a mid-way between front-end backend, it's a progressive back-end with long polling like NextJS I suppose. From your end though, it takes care of all the security of running your own API, and correctness. You basically have dynamic front-end from the backend.
If you want a full SPA or you need an application that is very responsive without network requests, I recommend VueJS - Livewire recommends AlpineJS, but of course you might be a React guy, that's fine, and use Laravel as a regular API.
You can even use GraphQL if you want to die of a young age, have some weird kinky thing going or you have something to prove... Unless you're Facebook of course you probably don't need GraphQL.
It’s kind of funny that this is the new best thing, when this is almost the same model JSF did decades ago.
If you do, please share your experience in a comment. I’d love to hear it. I architected this framework over the last decade :)
Your copywriting gives off strong old school enterprise sales vibes with a dash cryptomania. You are not going to get much organic product led growth among the US under 40 crowd here. I suggest taking a look at https://payloadcms.com/ and study their design, execution, and copywriting.
I checked out payloadcms though, that site is pretty terrible…
But in any case, great job with the platform!
That said, PHP does have complexity to running like node does with pm2, Apache or Nginx in front. Is it as bad, depends on the person, but it does suck IMO.
Fast, the most overrated feature that we developers endlessly look for. How fast? How much are you winning, milliseconds, nanoseconds, picoseconds? It's extremely likely that if something is slow is because you're doing something wrong regardless the language and/or framework.
It's reliable PHP? Well, so are Python, Ruby, Go and other friends, right?
> Laravel is pretty darn rock solid.
Again, so are: Rails, Flask, Django and many other matured frameworks out there that have been baked for years now. Unless you pick some toy framework project written in a weekend I'd say there are plenty of rock solid options out there.
> Just ignore the fugly standard library inconsistencies of (old) PHP...
I'll just prefer to pick a language that narrows/discards that dark side as much as possible. Very long time ago I couldn't finish reading a page whose author painstakingly detailed every single inconsistent feature of PHP (literally it could have taken a whole day to read). After that horrifying testament I said myself to ever get my feet wet with PHP. Now in a team with PHP you will need to agree which "inconsistencies" should be left out either by adding some tool to automatically watch for that or educating onboarding members of your team.
> Oh and it's free. All of it. PHP, Laravel.
Aren't the other friends out there also free? All of them?
> When I consider the solutions of flask and microservices...
Flask AND microservices are two completely different things. You can have a full fledged monolithic Flask application or go with the microservices rabbit hole with ANY technology and/or programming language that you want.
So PHP, well... Nah. At least not for me. There are plenty of interesting languages and technologies out there to be learnt and PHP for me is definitely not one of them.
One question aside out of ignorance. How do people debug in PHP? Many many many years ago I worked for an extremely short time for a company that were heavily using Laravel. I didn't know how to debug a PHP program at a time. People told me to simply do "prints" to the rendered template. If I remember correctly I also tried to find some tutorial or howto on debugging with PHP only to be unsuccessful. I'd be interested to know because with Python is just a joke to do that. Install ipython and ipdb. Then set `import ipdb;ipdb.set_trace()` and you are done, you get the full fledged mighty console where you can see everything you need to track down an issue. Up today I haven't got the opportunity to testify someone using a similar capability with PHP but hey I might be wrong and something of the like is out there.
Mostly xdebug. There is also ZRay on IBM if you use Zend, but I've never used it.
You could make it single threaded. But the standard is multi threaded, and if you have more then 100 users will be have to deal with locks.
That said, locks/threads are still easier to manage then async code.
Sooner or later I end up having to write Javascript and lots* of it. Therefore I use it across the board.
*where "lots" = logic that needs to exist on both client and server side
But it wasn't enough.
I couldn't fit the data set in memory with PHP. But I could do it with Go.
I couldn't do parallel computations in PHP in order to respond to an HTTP request quickly enough. But I could do it with Go.
I couldn't reliably and easily deploy to different systems with PHP. But I could do it with Go.
Eventually, I couldn't write a web server with PHP. But I could do it with Go.
A lot of my early websites were written in PHP and I was able to build them quickly and routinely. I didn't really have a problem with PHP as a paradigm, or even its security and consistency posture. I'm glad they've since made an actual language spec and fixed a lot of issues with it. And I don't judge or look down on PHP programmers. I just don't think it was the right tool for my jobs.
I remember after spending some time with Go, I got used to being able to process tens of thousands objects in memory in milliseconds. When I proposed to do the same in PHP, during architecture review, PHP devs thought I'm out of my mind because that would take like a gig of RAM (which would compete with other PHP processes on the server) and considerable amount of time. You have to use a lot of hacks to make it all fit in memory and be fast.
Our Symfony framework also initializes in like 300 ms on each request, while in Go it's below 10 ms. As every PHP process dies after serving a request, you have to reinitialize the whole dependency container on each request from scratch, and in large enterprise applications, that's a lot of dependencies.
Assuming that you're not spinning up and tearing down a container for every request, you want to be sure you're running php with a php-fpm configuration (preferably talking over a unix socket) -- this is the fastcgi process manager, which maintains a pool of "hot" php interpreters for you that are immediately ready to execute code for an inbound request. This is usually good enough for most applications without going into the weeds on things like opcode caching, but that's all available as options too.
I'd be happy to help troubleshoot this with you if you're interested. I've also got a fully automated build script that works pretty well. You can find my contact info via the link in my profile. I promise it doesn't have to take anywhere near 300ms for php to reply to a request.
I've never found it to be a problem on a VPS but if you're developing on something slow like a Raspberry Pi I can see this happening regularly. If you're used to deploying stuff in containers and constantly throw out the cache the initialisation problem can happen very easily as well.
Yes, the frameworks have obscene (java-like) class dependencies that build up during initialization (I'd prefer if there'd be a lighter function based framework nowadays), however for someone that knows how to manage PHP on the server there are OPCache tweaks, preloading facilities which help improve the request initialization performane (these steps are also expanded on in the symfony docs).
The share-nothing arhitecture of each request is either a benefit or a downside, depending who you ask.
>there are OPCache tweaks, preloading facilities which help improve the request initialization performance
I remember we disabled some of the settings for preload because we hit a bug which manifested as a segfault due to PHP's shared memory space for preload getting corrupted under a high load.
In any case, everything is fast and usually doesn't require a lot of tuning in Go out of the box.
However, I do love PHP's shared nothing architecture for the reasons of memory isolation: we have thousands of B2B tenants and with PHP, I'm confident we won't accidentally spill one company's data into another company's account. Things like when ChatGPT exposed your conversations to random people because a bug in the Redis connection pool inside Python's shared memory space returned a connection for a different user, due to a race condition.
Its not magic though, and I'm not surprised a compiled executable is many times faster, especially for math heavy stuff. Slow is often "good enough" though and deploying is quite straight forward.
If you’re willing to give up magic, it’s worth it.
The Symfony container does not rebuild in production and requests should easily be served within 5-10ms as well so you might want to check your deployment pipeline and that you correctly composer dump-env prod
Probably a configuration missing.
Check these Go vs. PHP benchmarks. PHP is quite fast and stands up nicely to the performance you get out of Go.
https://www.techempower.com/benchmarks/#section=data-r21&l=z...
PHP was the right tool at the time especially when everything on the web was somewhat Wordpress first. PHP felt like a blast with WAMP/LAMP.
Since then I have moved on and honestly it never occurred to me, that PHP still could be an option in my tech stacks, neither one of my devs recommended it.
No one hates or disliked PHP, there are simply other options.
Looking back, recommending PHP today feels like "You can do this with jQuery, too" in the Frontend domain. Yes, you can, but maybe you shouldn't or only if you have the right people. And PHP is a rare skill now.
I did write a REST/JSON API in PHP 5.2 (two years ago, I'm aware there's newer versions out there but they aren't easily available in RHEL 6/7 used at our customers at the time - it was a slow moving industry); it's doable, and using best practices learned from other languages makes it look maintainable at least.
Did run into some issue with large datasets though, but that was an implementation problem; the original author would read a CSV, convert it to XML using concatenation, then parse the XML to convert it into JSON because at some point a decade ago he found out that the X in XHR was no longer (and never was) the norm, all in memory. That broke when there were more than a few thousand rows in the CSV.
>I couldn't fit the data set in memory with PHP. But I could do it with Go.
I guess this on is self-explanatory.
>I couldn't do parallel computations in PHP in order to respond to an HTTP request quickly enough. But I could do it with Go.
Consider the following (covers both statements above): you need to get some data from a few sources (databases etc) do some computation on each set and then do some sort of mapping to get the resulting set. You may want those computations to run in parallel and idealy you'd like to start mapping as soon as each computation function starts producing results.
>I couldn't reliably and easily deploy to different systems with PHP. But I could do it with Go.
I haven't been using PHP since 5 but I assume it's still much easier to just push you Go binary to a destination.
Though with Docker and company deploying PHP code is not a big issue these days I assume.
when would you ever have a website serve a request, and have to use gigabytes of memory to do so?
> Consider the following (covers both statements above): you need to get some data from a few sources (databases etc) do some computation on each set and then do some sort of mapping to get the resulting set. You may want those computations to run in parallel and idealy you'd like to start mapping as soon as each computation function starts producing results.
Again, why would you ever have an HTTP server do so much work in order to serve a request?
This definitely sounds like a typical situation for handling the job in a queue (plus with an async library like spatie/async to retrieve data in parallel), though I see the advantages and convenience of using a natively-async language here.
Sadly this article is the latter.
I'm working on both sides of the fence -- dynamic strongly typed language (Elixir) and static strongly typed languages (Golang, Rust) -- so I am already sold on the advantages of dynamic languages. That page is doing a poor job selling PHP to me though, f.ex. it's not clear when you do `$request->user->orders`, does that automatically go to the DB? Does it first fetch the user and then all their orders, or does it do it in one go? Is the whole thing prone to N+1 queries like Rails is (was? no clue about it nowadays)?
Posting cute little coding snippets is skipping 99% of the story. The code must remain small and simple and understandable and easy to dissect / troubleshoot, long-term, and allow for adding metrics / telemetry, analytics and such.
So OK, we get it, you're so hyped about PHP that you made a website about it. Alright. Now do a cookbook. Next show us a 5-year old project and tell us how long does it take to add a feature or fix a bug exactly. Tell us of the issue that took you the longest to troubleshoot -- and why did it take so long.
Before that this is basically a surface-level marketing page that says almost nothing and is not even accentuating the strong sides of your loved technology because what I am seeing here I can clearly remember 5 other languages I've done it successfully with: JS, Golang, Elixir, Rust and Ruby.
Rails has had the ‘include’ method which solves n+1 since version 3.0 around 2010. Before that it also had preload which worked similar.
But islanders and continentals dont talk or help each other.
You can obviously build from scratch a blog, a wiki, lms, forum, analytics, e-commerce, survey etc. etc. site in Laravel. The funny thing is that it is quite likely that the leading open source solution for what you want to do is already in php (wordpress, mediawiki, etc) yet you cannot benefit much from it. You definitely cannot import it, but you cant even learn easily from it unless you dig deep into a complicated codebase.
Because php is so old and so adapted to web development people went on and built wonderful things with it, capturing complex domains with all their peculiarities. But that valuable knowledge base remains fragmented and locked within each one of these monoliths.
Going forward there is ever more intense competition between open source language ecosystems. A lot of improvement efforts look inward (making languages faster, safer).
The php community might also be able to draw unique advantage looking more "externally", taping the enormous domain knowledge of all these projects. How that could be done in practice is an open question, but it could become the USP for php, the way data science has become for Python.
It’s important to try to improve the reputation so that it gets new developers interested in it in order for the language to keep being relevant.
If you want a concrete reason why I think php is great and has many things that are very useful compared to its competition:
Extensive native support for classes and types.
Php does class-based OO better than its competition (JavaScript, python).
Designing a traditional object oriented system using classes and interfaces is better in PHP than in JavaScript and python, if we limit ourselves to the native features of the language.
For example, you cannot define a native interface or an abstract class in python or JavaScript. JavaScript classes, since they’re just syntactic sugar, have a lot of unexpected behavior.
In python you have to accept the this/self object in every method definition.
Here are a couple of links about php classes, interfaces and types for anyone interested:
- you make bold claims about PHP OO
- you make downright false points about other languages
- you nitpick things that are non-issues in other languages
All in all, nothing in your post really seals the deal about PHP. It's not about mocking or looking down on PHP for no apparent reason. I'm pretty sure most of us on HN have used it already and most of us have followed its development. I sure did. And every time a new version comes out, I welcome the improvements although it's just mostly catching up with the competition. So what compelling reason do I have to use it again in 2023 for greenfield projects ? None. It used to be "the web specialist", but now all platforms have great web frameworks along their distinctive features.You can meet people fresh out of university telling you that PHP is bad even though they have never written a line of PHP. They just know.
This is quite bad for the industry as a whole, because it plays right into large companies that is pushing their technology in an effort to subvert web.
Modern PHP is about community standards, not about any particular framework and exposing Laravel as the best way to get started with PHP is questionable. I wouldn't recommend it to anyone wanting to learn (real) PHP.
The article praises PHP but it is sad that doesn't link to any other resource or project which ditches the value of PHP community.
Laravel is great for RAD which is attractive for small projects. The kind of stuff "business with 500K orders runs on a $6 VPS" thing. For clients wanting a robust software system you can use a better tool.
Honestly asking. Haven't written PHP in over 20 years.
Seriously, though, I myself work for an enterprise that runs big parts of the European energy grid and we use Laravel for all sorts of stuff. At a previous job Laravel powered a whole ISP.
Notice when people say Laravel is good for small stuff and early prototypes, they never explain why.
That's quite misleading however
We used a function like findOne() (I don't recall exactly). It looked like this:
$resetTokens->findOne($GET['password-reset-token']);
The issue was that findOne would accept wildcards, so one could use ?password-reset-token=% in the URL and reset the password of any random users.
The snippet also validates request inputs, so clearly it doesn't assume that inputs are safe.
If an app stands the stress test against say for example this comprehensive list(1), it can consider itself somewhat safe or at least benchmarked. Otherwise, only vague and unsubstantiated claims, which does not help PHP nor any other programming language or framework.
i.e. $request->query(‘password-reset-token’);
This seems like a pretty basic thing to fix, but then I only have your snippet to go by.
I also Googled to check CSRF protection and all the sites I can find just discuss rolling it yourself; the example uses some CSPRNG that can potentially return not cryptographically secure numbers without erroring. https://www.section.io/engineering-education/csrf-protection...
That's one thing that really drove me away from PHP. It presents an extremely simple seeming universe, in which web apps are very easy to write – but has really naïve bones, requiring a lot of extra scaffolding to be safe.
Take this template:
<h1>{{ title }}</h1>
In most templating languages, for a title of "<script>alert();</script>", the result will end up being: <h1><script>alert();</script></h1>
In PHP, which is a templating language, the equivalent seems to be: <h1><?php echo $title; ?></h1>
But this will print the title unescaped, which is a security vulnerability, and incorrect. In reality, the equivalent is: <h1><?php echo htmlspecialchars($title); ?></h1>
Now, you could say, don't use PHP as a templating language! But if you're not supposed to use PHP as a templating language, why does it behave as one? This is one of PHP's footguns to be avoided. Personally, I recommend a linter like PHPCS to catch issues like this one.But I really like compilers, they catch a whole class of bugs, before I run things.
I can't imagine not having Psalm or PHPStan in our build pipelines.
There are tools for creating stand-alone executables from PHP source code, but they're not as nice to use, compared to languages that were designed for this. By distributing software I also mean making your latest code live in prod.
I suppose the benefit of using PHP (or other interpreted languages) is that it's easier to create "plugins", just copy the new source files to the server.
Also, out of curiosity, are all of those tests hand written, or is there some generation in there?
Oh and the garantiert that no one can modify it post the compile step.
Really? I see no evidence that this is happening
High profile posts over bundlers, tailwind, and microservices set the scene.
A few popular people on Twitter have been talking about Laravel which has influenced other devs.
Wind is in Laravel's sails, not php's
That's like, what, 12 orders per minute? Is this meant to be impressive or something? I bet any language run on a modern laptop can handle that.
Dropping half a sentence will often make it sound goofy, yes.
The point being made is "you don't need a massive K8s infrastructure to handle hundreds of thousands of orders a month". Most people don't; https://www.joelonsoftware.com/2001/04/21/dont-let-architect... is an oldie but a goodie on the subject.
This is true of many languages that are slower and faster than PHP. It's not useful as evidence of PHP being a better choice for anyone.
It's an argument that raw language performance in this sort of context isn't going to be the problem for 99.9% of people developing code. If you have 500k orders a month, you can afford more than $6/month in hosting.
I sometimes see folks post on StackOverflow trying to micro-optimize things like string concatenation or single versus double quotes that make perhaps a second of CPU difference in a million executions. The point is directed at those folks; the ones who are thinking "language X is faster, and for that reason alone I should use that instead".
On top of that, You don't need massive k8s infra for any other framework either, so it isn't really a selling point for PHP itself.
So with hardware specs better than the Chinese laptop I bought second-hand for 150 EUR (which has a Celeron J CPU), the very same one that can serve 2000 req/s on Elixir and 5000 req/s with Rust, then?
Sure, waiting on the DB is often 95% or more of the request, I get it, but 0.2 requests per second (which is the 500K orders per month when you do the math) is nothing to brag about regardless of which language or DB are being used.
It's even below the level of having a bash script doing the heavy lifting.
Also the numbers are still irrelevant for the server because if you do 500k orders a month you owe it to the users to respond faster than 1s and also be highly available (just take 3 servers somewhere idc about anything else)
First off, there is a surprising number of core behaviors you'd expect from a modern web application that there isn't a clear go-to for in the PHP world. Does anyone know of a well maintained library for publishing and consuming AMQP messages asynchronously?
PHP is still limited by living inside of the context of the request. This has an effect on certain types of application-layer caching, and makes for a poor model for backend scripting.
You also still need to interact with multiple layers of dependency management -- from os packages to pear packages to composer libraries. Configuration can be messy, and many projects still aren't containerized.
Finally, while the language has evolved, many of the projects that use it have not. The longer lived the PHP project, the more likely you are to encounter the exact paradigms that make it so hard to work with. Other languages have benefitted from a much greater percentage of their lifespan being supported by ecosystems that encouraged keeping your dependencies and the parts of your code that exercise them up to date.
That being said, it's great to see that there is a path for starting new projects with a modern framework. But I would have said the same thing about Zend or Symfony, and those seem to have fallen off for reasons I don't know.
Some of your complaints are a little weird. * The OS package/pear package thing is highly dependent on what language features you want to add to the base language. If you want, you can install all those features with pear. It's just easier to install with OS packages. * Composer used to add libraries to your code base * The fact that "many projects still aren't containerized" has nothing to do with PHP. I doubt there are many languages where that statement isn't true. * No idea why you think Symfony has fallen off. Laravel has large chunks of Symfony code inside it and the project is going strong with regular releases.
How many seconds in a month? 60 * 60 * 24 * 28 = 2,419,200.
So basically, its performance is at least 0.2 requests a second...
(Not that I want to defend Laravel's speed, it's not really anything to brag about, and the typical "cache everyhing everywhere all the time" aswer is not that useful.)
Not to mention that as long as you have a direct sync query to a database - your code will have to wait, lol.
OTOH it makes a point that it solves a real problem. A business processing 500k orders a month is not trivial.
It all sits in a single 5 year old machine with 8 cores and 16GB RAM. Their bottleneck is actually MySQL but they have room to spare so no need for upgrades right now.
If starting a new project in the space where they all “compete”, I would choose PHP7 or PHP8 with Laravel or Symfony (or maybe even WordPress) over Rails, Django and probably over NodeJS.
Ive a lot of love for WP, but I don't really get the appeal of extending it past blogging... if you're doing anything more complicated it's pretty trivial to implement blogging functions in your site.
Even the data structures in a default WP setup, making everything as post types is silly for anything not a blog and I wouldn't build anything on top of that ever again. Most of the examples (all I ever saw?) for themes are silly, because they use concattenation for HTML templating, instead of composition. Not long and a theme will become messy, unless one is very vigilant, but then code reuse inside the same theme obviously suffers.
Basically the whole ecosystem is full of anti patterns that one would avoid usually, but that somehow have become the tutorial samctified way to do things in WP.
I just wonder if a lot of these shops would be better off starting from something like OctoberCMS or all the Laravel add-ons like Nova or Spark which give you Admin and Billing UIs pretty instantly?
- non technical someone wants a CMS
- I tell them I'll build them what they need, then give them a quote
- non technical someone doesn't like my quote and installs Wordpress and a gazillion shiny plugins, because "it's easy with the shiny admin panel and I can install it anywhere for cheap and all the functionality is already covered in plugins"
- things break, because plugins are meh
- things go real bad, security issues, loss of data, shitty performance, the whole piñata
- non technical someone cries over the phone "can you fix my website ???"
- I won't fix their website because I like to build things, not clean up someone else's mess. Feel free to fill that business opportunity but I want to do something else.So you never know what or whom you gonna get, but the bottom line is if you have sales and revenues and keep tabs on spending, they will come, and they will not care less about your fancy framework or newest code implementations.
TLDR: code in whatever you feel comfortable but always consider security as top priority (not speed) because in production your code's/setup security mistakes can cost you serious legal troubles.
Every. Dang. Engineer. It’s crazy.
I try to work in a codebase for 3-6 months before coming to any wild conclusions. Usually you find that there’s some warts but it does the job and there’s complexity that was solved that you hadn’t originally noticed, and it’s not worth rewriting it just needs some love in some areas.
People hate reading other peoples code.
The current project has had numerous iterations on requirements over the years, changes in project leadership, paradigm fads come and go, and all that time accumulating cruft and layers. Looking at it at a single moment in time, you have a fixed set of current requirements where all the discovery has already been done, plus whatever your current knowledge of future requirements is, possibly none of which may have existed when the original code was written.
That doesn't mean that everyone is going to sit around on their thumbs patiently waiting for you to rewrite it to be perfect. The more lines of code there are, the more time it will take, and the more hidden features that nobody really remembers exist but are still crucial will crop up.
Few situations are actually best served by a full rewrite, but almost every project would be better off if the world could stand still long enough for it to happen.
What usually happens instead is that the rewrite happens because the original code has been handed off to a new set of people. They're not deeply familiar with the code. It's confusing to them. It's not obvious why things have been done in a specific way. And so they decide rewriting it from scratch is the better option.
Unfortunately, they're not in the best position to come up with a solution that incorporates the right lessons from the original design.
just ask WordPerfect.
any kind of home grown business app will have corner cases and requirements spaghetti that would take much more time to figure out than to write actual code.
and if the person asking you to do a rewrite just shrugs when you ask "where is the test suite?" walk away asap.
1. with http://sqlc.dev I don't have to write ORM or model code anymore. Define all your SQL in an easy to audit file and all your models and interfaces are generated for you.
2. with http://goa.design I can have well-documented OpenAPI API's that any team can generate a client for in any language. It also generates the HTTP JSON and gRPC clients/servers for me so I can focus on my logic.
3. with https://github.com/99designs/gqlgen I can define GraphQL revolvers that play well with sqlc (any RDBMS) or I can use a key-value store.
4. speaking of key-value stores, Go allows them to be embedded! Even SQLite now has the https://litestream.io/ project to make it super simple to use a durable, always backed-up SQLite database even in a serverless context.
Go is faster, uses less memory, uses types, has built-in formatting, package management, benchmarking and testing. Go supports multiple cores in the same process, and has really-well designed stdlib without all the bugs I used to face trying to use the PHP stdlib.
After writing millions of lines of PHP for years, there is nothing I miss anymore. Laravel still wants me to write models, controllers and views by hand and make all the client changes as by-hand code refactors.
Go lets me focus on the actual logic instead of waste my time in PHP writing all the implementation details like controller requests handlers, db fetching logic, and input validation.
The language has evolved since. The ecosystem has evolved since. Most of the things you're complaining about are solved paradigms that no one does manually anymore unless they're trying to drastically improve on ecosystem tooling.
Even your complaints about Laravel are solved by open source tooling in its own ecosystem.
Nothing about your preferences are really unique to go - most, if not all of these tools exist in many popular languages.
The one solid point you have is that go lets you do many of these things by default without adding anything. To which I say: Duh. Go doesn't have a massive ecosystem of backwards compatible projects to continue supporting. It was barely used outside of niche cases until 2-3 years ago. In 10-15 years time, I'm sure people will say the same things comparing Go to a newer language.
1. SQLC is little more than a template generator for Prepared Statements wrapped in a class. [https://www.php.net/manual/en/mysqli.quickstart.prepared-sta...]. It's not exactly a mind bending or time saving tool.
2. There are multiple OpenAPI generators for PHP, in fact, they existed from nearly the start of the OpenAPI protocol (formerly Swagger) when Go was barely a year old. Here's a current popular one: https://openapi-generator.tech/docs/generators/php/]
3. PHP also, (unsurprisingly given the origination point of the spec) has many GraphQL implementations that support any database driver over ODBC, key-value stores, or even flat files. Here's one that plugs into Laravel [https://lighthouse-php.com/]
4. PHP has many mature, modern embedded KV store options... but it's also had one in the standard lib since years before Go even existed, or the concept of KV stores was even popular. [https://www.php.net/manual/en/class.splobjectstorage.php].
On your non-numbered points...
Go and PHP are fairly similar in raw processing speed since the JIT was added to PHP. However raw number crunching is rarely realistic when most applications are going to be using databases, stores, etc. So why not look at a benchmark of popular frameworks in both languages - which shows, again that the two are fairly similar in performance. [https://www.techempower.com/benchmarks/#section=data-r21&l=z...]
PHP has also had types for about 4 years now. It's not statically typed, but that's a preference, not a pro/con situation.
Built-in formatting is also a preference, not a pro/con situation. Many developers strongly dislike languages like Go and Python for this.
PHP has had one of the most powerful and useful package management ecosystems in the entire open source world since composer mostly replaced PEAR nearly a decade ago. It also has mature and well loved testing tooling. Neither of which are built in, because why would you need to build in tools that the community already creates and maintains for free?
I don't know what "bugs" you faced in the PHP stdlib, but I will concede that it is painful to use. Most of the stdlib is little more than a wrapper around C functions of the same name, and they inherit the frustration of using those C functions.
Laravel does allow you to write things by hand. You can also just define them ahead of time and have the Migrations, Models, Controllers, Views, Transformers and more generated for you automatically. [https://blueprint.laravelshift.com/]
There you go, there's your links. But frankly, you didn't need them. There's little you mentioned that's unique to Go at all, you just named a bunch of things that have become popular tools for most modern languages still being actively developed. I'm not sure why you think any of these things are Go-specific - some of them are maintained by the Go core team, like other newer languages have started doing, but that's it.
PHP is very good for writing services that cost literally nothing because you can run it on free hosts like 000webhost that give you everything you need to host complex services (upload, database, sub-domains, and more.) It's perfect for budget devs or maybe devs that want to make their infrastructure more resilient to ah... financial upsets...
When I was a teenager I used to host sites on an old android tablet. These days if you have a credit card, you can make use of the free plans most platforms have and free credit, especially if you have an .edu email.
Nowadays instead of using 'string_you_have_to_remember_and_might_mistype' or abusing associative arrays as in the given code sample, you can usually get full code completion luxury with PHP without magic comments or other workarounds.
PHP 8 is still missing a few critical features such as generics and typed resource handles, and nikic left the project, but I'm still hopeful PHP 9 will deliver on those key additions.
It's a Laravel package and it's the best CMS I've ever used (from a dev perspective). v4 just dropped the other day
I believe Craft and Statamic share a root in ExpressionEngine, which I loved also. I've only used Craft a little bit, for me the biggest issue is that it is (or was when I last looked) built on Yii, which isn't my go-to framework in PHP.
This is in no way a showstopper.
I haven't used Kirby, but it looks like a completely stand-alone application so I'm going to miss being able to co-locate the rest of my application there with the full toolset of the framework behind, which for small sites I really appreciate about Laravel+Statamic having right out of the gate.
I've also not used Twill, but it looks to be similar to Statamic (as it's also a package). Not sure how this can be more open source than Statamic tho... if you mean free as in price, I'm all for paying for great products to make sure the teams behind them can keep on churning out great work. I'm sure AREA 17 will keep supporting Twill for a long time to come, but it doesn't look to be the focus of their business.
I'm also intrigued to know what you mean by "better at flat-file".
UX of the admin interfaces is kinda subjective and less of a concern from a dev perspective (though it's still an important consideration if you're trying to pick the right tool for a client or another team!)
> they call themselves Laravel based for marketing
Same goes for Twill :) nothing wrong with hanging onto the coattails of a popular piece of tech
AFAIK Statamic wasn't built on Laravel at all in the beginning. I believe Jack adopted it because it was clearly a great stack to build on top of. I think he made a great choice and I'm glad of it.
I don't think it's a good idea to have your product and your presentation website in one app so for me it's not a feature. They should really be separate concerns.
I haven't used Statamic 4 yet but last time i've used it they didn't seem to use much from the Laravel. It basically publishes routes to Laravel from their own system and that's it. It even recommended it's own templating language Antlers. It just feels they want to really ride the Laravel wagon while still being just separate system. Thats OK but Twill for example really depends on Laravel and feels more deeply integrated with it.
Craft is good simply because it leverages database powers well and it's super mature. Things like relations and search are a lot harder in flat-file systems. Twill does this OK. Flat-file systems generally have ways to use database but it's more work. I would pick Craft for sites where having DB is more advantageous than flat-file.
Kirby is kinda it's own thing. It's oldest and mature, simple, steady but modern. It tries to have as little abstraction as possible. Opposite philosophy to all Laravel magic. It's kinda edgy and zen because of that. The advantage of less code and dependencies - it's super fast and easy to read source code. Not that it would matter in a CMS. Kirby embraces flat-file as kind of nosql database. For example every page has unique identifier that is indexed an can be referenced anywhere. I don't know about CMS that does that out of the box. And Kirby admin interface is also pretty different because it has no preset ways. When you install it it's empty - you have to completely define it. This can be huge advantage or more work for developer depending on what you do. It's more like build your own CMS package than CMS.
Statamic has inspired lots of their features/implementation on Kirby and for years played catch up. Nowdays they are all very feature rich so it's more matter of taste (and price). Statamic has one really nice advantage and that's GUI blueprint builder. If you hate writing YAML to define admin area (which both Kirby and Statamic need) with Statamic you don't have to.
If you're developing an application that needs to account for such an edge case you could easily do so with an insert w/ join method on the Order model. The author isn't trying to show that the code is bulletproof for every scenario.
The right tool for the right job, etc. etc.
I haven't touched PHP since 5th version and I'm kind of sceptical it can offer anything RoR can't.
Just a few examples of such PHP script:
1. an endpoint that is being called by my CI to send messages on IRC and telegram when a new build is ready
2. the analytics bit of my project so I know who does what without relying on google analytics but by storing all that stuff in a mysql db. It's under 25 lines of PHP code and has worked a lot better for me than any analytics tools I've tried: https://gist.githubusercontent.com/mickael-kerjean/289d3d0be...
3. the target of the contact me form of my project
4. all the webhooks and other simple marketing automation stuff I need to process one way or another
5. all sort of online tools relevant to my niche to boost the SEO side of my OSS project
6. my status page which is an array of url I look after that is being curl around
7. crud cloud instance of my OSS project
and many many more examples, got about a hundred random stuff running from a single cheapo VPS I don't have to maintain.
He just drops a PHP file in a folder and be done with it, it just works.
I think in the end the competition will lead to specialization. Python will almost certainly capitalize on its data science / ML links but its not clear (to me at least) how php and ruby will differentiate themselves.
I was just curious to be honest. With RoR being what it is PHP frameworks has to offer something on the same level (at least) to be of any interest (as a I see it). Not to mention ecosystem\packages\gems\etc.
Some of the most fun I ever had writing basic CRUD apps and simple interactive websites was in PHP and Codeigniter back in the day. I'm pretty much Team Python now just because of the huge ecosystem but maybe it's time to give PHP another chance...
PHP was always a mess. Why would I want to come back to it now on the off chance they don't screw things up again?
array_filter and array_map, have different order of arguments.
($array, $callback) vs ($callback, $array)
A small example of how inconsistent the language is from the ground up.
Most people can explain their respective web servers, but I've never heard anyone even come close to what PHP/Laravel is actually "doing".
Side Complaint: If you are working with Laravel Queue, it is such a hassle to reload your code changes when developing.
Sadly the site got a refresh ages ago and is nothing like it used to be.
Anyway, if you're reading this thread, thanks Jeff!
Is this a statement from the real world? What business sells 500,000 orders in a month from a $6 server? I mean, if you sell that much, you would probably want a high-availability solution and they don't sell for 6 bucks.
Just use two 6$/month servers.
Hilarious because other languages are capable of that per minute not per month
I'd at least expect that to be possible in Node, and would be somewhat surprised if a Go or Rust framework didn't hit that mark.
Hello world will work, but once parsing, validation, and database queries get involved, you'll need some beefier hardware to get those numbers.
I can't get the cloud benchmarks for 2022 to work (a dedicated PowerEdge is the standard physical benchmark and that's not very realistic here), but according to these benchmarks: https://www.techempower.com/benchmarks/#section=data-r20&hw=... you're going to need some very optimized code to get close to 8k reqs/s.
1. PHP the language and developer experience (frameworks, tools, community, docs, etc)
2. PHP performance at scale
In my experience, PHP is much improved for 1. and fine to work with. Laravel and composer are great.
For 2. I would never use PHP on anything above a few hundred requests a second. It's slow on its own, but more importantly it's blocking IO model will grind things to a halt at any level of concurrency when talking out to database, caches, or other services. You are also vulnerable to issues like saturating your database with connections due the programming model in php-fpm. I know async php exists but my impression is the mainstream frameworks dont support it (I could be wrong?) so why not just switch language at that point. I speak from experience of scaling a Laravel php app up 5k RPS+ and needing a LOT of EC2 instances to do it. Using Go was a revelation and delivered a 10x improvement in terms of resources required to serve the same number of requests.
So yes, if your rps < 500, why not, PHP is fine. For anything above that, it's a not a great choice.
(And defining your scale in terms of orders per month is a bit silly)
I have the same experience as you, I've participated in migrating from PHP to JS, to Elixir, and to Golang. The transition to JS was mostly a performance disaster (not much performance was gained) but at least more devs could help so it was still a big win organization-wise, whereas the transitions to Elixir and Golang were a screaming success on every front: we immediately gained anywhere from 7x to 25x more req/s and the DB load was stable and the request timeout errors dropped by 97.9% on the first day (and were completely eliminated a week later), not to mention the cost of our hosting also dropped by at least 70%.
I am past my phase of "hating" languages but honestly, saying "PHP is not the right tool for jobs X and Y" is a "hate" in the eyes of many anyway. And yeah it's not good enough for big scale. I mean, if you make $1M a month then you likely don't care much if you pay $50K in hosting, sure, but why do you have to spend 5% of your revenue on hosting? There are a lot of modern technologies with which you'd be hard-pressed to justify having more than 2 application servers and 1 DB server (with read-only backups and replicas if sh_t hits the fan).
Good to hear someone else has had a similar experience. Nothing against PHP at all, but it's definitely not suited for scale.
That aside:
> It can handle more than 500,000 orders per month when hosted on a $6/month server.
Surely it can do more than 700 orders per hour, 1 order every 5 seconds?
> The only additional fees are for a CDN (if you want your assets to be served faster) and a domain name
Uh, so no managed database, but you recommend paying for a CDN before slapping Varnish in front of your static assets?
I get that php might be eminently usable at this point - but this seems like an odd pitch.
- hidden global state
- arbitrary string literals
Is that Laravel?
I hated it (Laravel) for those reasons, along with the madness that was the DI container. Guess I'm just not "web artisan" enough.
It was a largely pleasant experience, taking me back to my early years as a "web developer". I had to modify some PHP files because the theme used didn't offer slots for widgets in places I wanted it to.
That being said uncached the site takes over 20 seconds to render. CPU load wasn't high so I can't help but wonder what was it doing all this time.
Client had launched a product that was a bit more successful than typical. Nobody could access the site though. I dig around a little, come to find a neat little snippet of template looking for a featured user for some markup.
The genius who set this up iterated through each record trying to find the featured item. One query at a time, testing each record in the application for the flag.
Php is fine, some very inexperienced “developers” use it though so you find a lot of gems like that in the space.
If you're wanting to build a TUI I haven't seen any libraries as advanced as the Python or JS ones.
But it really depends on what you need the command for.
I use Symfony command for general things, Node.js for eg PDF generation, Python for ML, Rust for calculating Ranks/Scores
Development time is the same for all of them.
For whatever reason Node.js scripts always feel dirty to me. I can not even pinpoint why.
Use PHP if
- you're in a hurry and you already either know PHP, or the script is going to call other PHP code you've written
- execution speed is not important (ditto for Python and Node)
If neither of the above is true, give Rust a whirl.
This experience was pretty disappointing, but also pretty niche. Overall I agree with the general sentiment that PHP is very nice to use nowadays, especially for web development.
For those who know PHP, this code is full of singletons masquerading as static classes (which Laravel incorrectly calls "Facades") which mean no isolation and clear flow of dependencies in your code. In a nutshell, every line of code you write this way comes loaded with a pound of irreducible, unfixable tech debt. Enjoy.
And worst of all, you are stuck with a shitload of churn every time a new Laravel version comes out. But this is true for Rails and CakePHP and probably many others as well. At least Django seems to be moving a bit slower and not deprecating loads of features on every release.
And from first-hand experience, while the specific code sample shown on this page shouldn't be treated as a practical example of how to architect a larger application, there's nothing compromised here in terms of performance or testability.
All tech is tech debt at some level or at some time - what has happened to pragmatism? Laravel has actually helped me write the most performant, tested and least-refactored code I've ever written.
Like any tool, used properly it will do its job well; simply grumbling and shooing it away does not stop it being a perfectly fine tool in the right hands.
Oh look, you even say so in your own comment: "the specific code sample shown on this page shouldn't be treated as a practical example".
So... you're saying the page makes it SEEM simpler than IT IS, hmm? Is this what you were asking me about "why is it bad"? You don't think parlor tricks in demo code is a bad thing?
So what are you even objecting to here? I said something bad about Laravel, and you use Laravel, so you have to go on the offensive out of loyalty? I don't know why people need to identify so religiously with their tools. If we start picking apart this demo code, you'll probably admit that every line contains an anti-pattern you'd avoid in a real project of more than a modest size.
So what is this demo demoing then? It's essentially misleading people about what it takes to write a good app. If we'll go by simple demos alone, PHP needs no framework at all for a good demo:
<?php
echo "5 + 5 is: " . (5 + 5);
Boom, everyone understands this, now you can write your own Google!This is why RoR declined and it's why PHP with Laravel and WordPress as their poster boys is declining.
PHP itself is no longer as terrible as it used to be, although all the good people seem to have left the internals. But the frameworks people use on it are terrible, incompetent and aggressively misleading people into bad practices for the sole purpose of marketing to newcomers.
More or less directly opposite of what Laravel is preaching. It's the popular choice for anything that is being build long term. It is very popular in Europe and we have a far bigger community around it than Laravel does.
5 + 5 = <?= 5 + 5 ?>
why use echo? php _is_ html :DArchitecture: The default structure of the app is good to start out and can be changed at any time. You are not locked into that. If you apply your fancy patterns, you can do whatever you want. It's rather a devs fault than the frameworks fault.
Performance: Guess depends on what you compare it to. Surely a rust service will be more performant, however you can scale laravel just fine if you are not writing shit code. There is enough apps built in laravel that handle more load than the average pro reddit coder will ever see.
Testability: Not sure what you mean, you can test in different ways and anything you need to test. It's fairly simply too. Yes, there are sometimes issues where you can run into memory leaks but those can be fixable after some digging.
You can but don't need to use facades, you can go full DI, you can swap the IC.
The Irreducible, unfixable tech debt is created by the developer that wrote it and does not know php or laravel. Yes, laravel makes it easy for newcomers to get right into the traps you mentioned, but then again - we are talking about junior that would not know any better and probably would fail without it.
What you call "full DI" in Laravel is still globals in disguise, because there's a single global container.
Most defense of Laravel comes from people who have no idea how to write a good app. And unfortunately, due to bad frameworks, the number of those people is multiplying. I blame Spring and RoR. So much pain came from them. Laravel is just a pale copy.
But it's nice to be reminded, I guess, PHP isn't the dumpster fire it was 18 years ago.
15 years later I joined a marketplace startup that was doing 10,000 transactions a day.
Built as a PHP monolith.
I was sooooo confused at first. “PHP??? That strange language I used to host a forum is powering this app??”
Turns out the founding engineer was self-taught and PHP had the most tutorials or something lol
Starting with Laravel support and launching soon
$request->user()->orders->create($request->validated());
This looks so wrong from an architectural point of view! A request has a user (which in the context of HTTP should be more or less only an authenticated principal), which has orders, which are created from the same request, where the journey started. There is no separation of technical and business concerns.See: https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-a...
I recently rewrote a PHP web app in Rust (https://soapstone.mradford.com/riir/) and although it was interesting, I think it would have been better staying a PHP app. As nice as the Rust compiler was, I felt PHPStan would have automatically caught a similar number of bugs, all the while feeling less combative.
The problem is how easy it makes it to write obscenely unmaintainable anti-architected code bases in it. The average PHP production code base is deeply offensive. I'm knee deep in one right now.
You can still have awful code bases in Rails or Django or Go, but the opinionated nature of those ecosystems makes the average much better than PHP.
If "PHP" were synonymous with "Laravel", that would be different. But it's not.
it has orders of magnitude less complexity than the JVM, or even the various Python server runtimes (gunicorn, uwsgi, etc)
at least in my experience. can you elaborate on what you see as the debug support deficiencies of PHP?
I can set breakpoints in my react app too, but it feels weird to inspect code in the browser console. And since modern frameworks get compiled for the browser, it is all even less familiar at a glance.
Or an advert by someone involved with Laravel/Laracasts.
As the former it's quite effective.
The latter would be funny.
Every popular piece of dev tooling in the PHP ecosystem feels like it was made to solve a problem, do so as simply as possible and let you know all the information as cleanly as possible.
There's contemporaries to most of those tools in every other major language, and all of them have problems or annoyances that I feel simply don't exist in PHP's tools.
and yes, Laravel use lazy comparison (hundreds of times). And yes at least three bugs where caused by this use.
see: https://github.com/laravel/ideas/issues/698 for why I'm a bit grumpy with php ecosystem
I’m asking because I keep hearing Ruby on Rails is the best for starting a SaaS, etc but from my little experience on it, it seems to me Laravel is way better. Is it just a “language” thing? That most people prefer Ruby to PHP?
I'd expect to see some discussion of async job processing and front-end web frameworks in any advanced web programming course, high-school or college level. Honestly, just teaching the usual react stack with a typical node backend would probably be ideal since JS is approachable, react is still "cool", and you still only need to use one language.
Alternatively: what would you suggest someone getting into web development to learn? PHP or Ruby?
The one with the best density of good developers in your hiring region if the application ends up scaling.
> Alternatively: what would you suggest someone getting into web development to learn? PHP or Ruby?
Neither. I would tell them to get into the Javascript ecosystem - not because I think it's necessarily good, but because that's where most of the work is. I'd also reccomend picking up at least one other general purpose language to be a bit more rounded such as Golang, Java, C#, Python.
Don't get me wrong –– Laravel (the framework) has some polished first party packages however, as soon as you step out to third party packages the quality drops significantly.
wordpress is also php. dont go with php.
I remember when Rails first launched and I wanted to try it but it was so complicated to get started.
Placing an order from the Web will almost always involve multiple requests.
Another language carried by tooling is Go. The language itself doesn't even have sum types, lmao.
Just because code reads well doesn’t mean you can understand easily what it actually does.
If I read this as a documentation page, this makes me scared:
`Order::create($validated + ['status' => 'pending']);`
What does it mean to add an array to something?
Order::create([...$validated, 'status' => 'pending']);
`$validated = ['key' => 'value']; $validated['status'] = 'pending'; Order::create($validated);`
No, because the example is showing concatenation of associative arrays. In Python, you'd use a dict, and you can't do `validated + {'status': 'pending'}`:
``` >>> validated = {} >>> validated + {'status': 'pending'} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'dict' and 'dict' ```
You can do `validated | {'status': 'pending'}` since 3.9, though. I think using union or the * operator (e.g. `{*validated, 'status': 'pending'}`) looks less weird, but if you're a PHP programmer, you already know what + does here. In the end, it becomes bikeshedding.
[1,2,3] + [1,2,3]
// '1,2,31,2,3'
(never tried this in js before; so was amused by the result)Depends on the context but in most cases these are a convenience, syntactic sugar.
Take SendOrderToVendor::dispatch($order)->onQueue('orders'), for example.
This could also be written as:
$job = new SendOrderToVendor($order);
$job->dispatchOn('orders');
(Exact function calls may not be correct, I'm on my phone)
Functionally identical - same code path. The main gain is ergonomics, but it's entirely your choice how you prefer to write this code.
Works a treat. It’s robust, fast as hell, easy to make secure, runs on the cheapest, crappiest hosting, and has an enormous support infrastructure.
That said, I’ve never particularly liked the language, and have never become an advanced adept at it. I use it to manage the less-glamorous part of my work. I’m mostly a native Apple developer (Swift).
Generally speaking, if you use PHP to build an API, you can use react still as is.
Jeffrey Way is a really good teacher, btw.