52 ms·
PHP in 2021
- chx 6y agoIn a post called "PHP in 2021" we really can't omit https://bref.sh/ https://bref.sh/ -- it allows running PHP apps on AWS Lambda effortlessly. With all the serverless craze, it's a very important piece of the ecosystem. After writing PHP apps for two decades, I am absolutely stunned how easy it is. Amazon blogged about it at https://aws.amazon.com/blogs/compute/the-serverless-lamp-stack-part-3-replacing-the-web-server/ https://aws.amazon.com/blogs/compute/the-serverless-lamp-sta...
- kijin 6y agoFor what it's worth, PHP has always been kinda "serverless". You just point the PHP interpreter at a file, and it runs the script contained in the file!
- slt2021 6y ago+1. PHP can easily host 1000 applications on a single node, while java people would struggle hosting 1000 docker contained spring boot monsters
- jfrunyon 5y agoMy sweet summer child...
- jfrunyon 5y agoThat's how literally anything which is "executable" works. You just point the interpreter (kernel, ld-linux, php, python, ...) at a file, and it runs the file.
- kijin 5y agoExactly, and PHP brings this simple intuitive behavior to the web. You just point your browser at a .php file, and the server runs the file for you.
- jfrunyon 5y agoSure, once you've set up the web server, and PHP itself, and installed (usually through a not-easily-wget'able link) the program you want, and configured it, and set up its permissions properly...
- muglug 6y agoFWIW Bref is cool, but it's AWS-only and still has a couple of orders of magnitude fewer daily installations than Laravel: https://packagist.org/packages/bref/bref/stats https://packagist.org/packages/bref/bref/stats vs https://packagist.org/packages/laravel/framework/stats https://packagist.org/packages/laravel/framework/stats.
- mtnGoat 6y agoNot sure they are comparable as they serve very different needs.
- porker 5y agoConsider that many Laravel installs will be done on CI servers.
- muglug 5y agoI guarantee that a larger % of the bref installs will be done on CI servers (bref is newer, and users of it are generally more advanced)
- yboris 6y agoI don't get it - the cheapest webhosts ($3/month) all let you run PHP - why would I need a cloud function when I have an always-on machine? And if it's for something with high traffic, why would you want a cloud function anyway? I thought they are meant for "runs sporadically, so why have a machine that's always on?" setup.
- paulryanrogers 6y agoWhen load varies you'll only pay while it's in use. Web-hosts without VMs or containers often promise a lot until you find their shadows limits. And those with VMs and containers can come out more expensive for some workloads. The landscape is changing too. So if your work is stateless or relatively low bandwidth, and has variable load then it's probably worth trying FAAS.
- chx 6y agoI am using a lambda to answer a webhook. The lambda function writes into SQS and in turns, SQS calls a queue worker automatically. Is this possible without AWS? Certainly. I was one of the two people who wrote the queue subsystem for Drupal more than a decade ago. And yet, AWS here does away with all the scalability concerns both up and down.
- mnapoli 5y agoWith your webhost, you have to setup and maintain the server, including patching/updating it, setting up SSL, etc. I used to do that for side projects, but I've had too many servers, and maintaining them was a pain. For something with high traffic, Lambda provides the instant scalability. Imagine servers autoscaling, but instantly. And again, without having to setup or maintain that.
- purerandomness 5y ago> With your webhost, you have to setup and maintain the server You're confusing a root server or a VPS with a webhost aka "shared hosting", where the hosting service takes care of Let's Encrypt certificates, and scheduled downtime for patching.
- ahofmann 5y agoSo since only a few decades I can do this: 1. create a shared hosting account for almost nothing (or literally nothing: https://www.000webhost.com/free-php-hosting) 2. write index.php 3. upload index.php 4. ??? 5. profit! But now, I can have the greatest and latest serverless multi-region, multi-something stuff with only these simple steps: 1. create AWS Account 2. follow these "simple" (nothing in AWS is simple) 4 steps to create AWS keys: https://bref.sh/docs/installation/aws-keys.html 7. #npm install -g serverless 8. #serverless config credentials --provider aws --key <key> --secret <secret> 9. #composer require bref/bref 10. #vendor/bin/bref init 11. edit index.php 12. #serverless deploy 13. ??? 14. no profit, because your stuff went viral and your AWS bill is killing you So at the end we have 14 steps to create something that potentially costs a lot and had an easier solution since about 1997. Awesome.
- busterarm 6y agoPHP has been in a pretty good place since 7, IMO. These are some great developments. I would say that Laravel is an extremely high quality framework (on par with and even in some ways better than Rails) that nobody should be ashamed to use. It's unfortunate that the stink of old PHP is so powerful and that salaries are still lagging so far behind.
- ggregoire 6y ago> It's unfortunate that the stink of old PHP is so powerful and that salaries are still lagging so far behind. Could it be that there are less Rails developers than PHP developers so the Rails developers get higher salaries?
- nicklecompte 6y agoI have wondered how much of this is also due to markets. A lot of governments and security-centric nonprofits (eg hosptials) use PHP instead of Rails, which seems much more popular in startup land. It could even be that PHP is used fairly evenly across the whole US, while Rails is used more on the coasts. Disclaimer: I don’t have hard facts or even anecdotes, I am a functional-first developer who marvels at any language which actually has jobs on the market :)
- devoutsalsa 6y agoRails also got traction in SF & other high paying areas at the right time. PHP had it’s chance to make establish itself in SF in the mid to late 2000s, but Ruby on Rails worked its way in as a fast prototyping tool that made efficient use of VC capital at a time that PHP was seen as a tool used by less serious developers. A lot of startups contact me about Rails to this day.
- jspaetzel 6y agoThey're not lagging behind. Based on my experience, companies in the bay area using PHP often pay just as competitively as others. There are likely a large number of "PHP" jobs available overall though which could bring average pay down, the low-end is low because there's such a low barrier to entry for something like WordPress development.
- yeskia 6y agoAs someone who works with Rails and Laravel, one of the huge benefits I find working with PHP/Laravel are the speed and consistency of releases. PHP seems to release versions more frequently, and Laravel tags every week. It means there's much less lead time to work with new features/functionality as it becomes available (when it's stable, rather than running on edge).
- dvko 5y agoI once came back to a Laravel project after just one year of working on other projects and had to go through several upgrade guides just to stay up to date. Most changes were quite trivial (yet annoying to make), like namespace changes and other things that should probably have been weeded out before ever making it into a release... It’s why I prefer Symfony if I absolutely had to work with PHP nowadays.
- tpetry 5y agoLaravel did release major versions every 6 months in the past. The changes have not been much and https://laravelshift.com https://laravelshift.com is able to it automatically. They‘ve now changed to yearly major releases because not everyone is able to upgrade every 6 months.
- timw4mail 6y agoWhen 7.4 was released, with FFI now available, I had the crazy idea to make a cli text editor in PHP[1] (based on kilo[2], and since 8 has come out, with the addition of the PHPToken class, highlighting PHP with PHP has gotten easier. 1. https://git.timshomepage.net/timw4mail/php-kilo https://git.timshomepage.net/timw4mail/php-kilo 2. https://viewsourcecode.org/snaptoken/kilo/ https://viewsourcecode.org/snaptoken/kilo/
- pdenton 6y agoMy beef with PHP is not so much the language itself, but the weird community that surrounds it. The FIG standard that forbids TAB for indentation (which is perfectly legal in PHP), the notion that classes should be either abstract or final, the micro-optimizations (thou must use single quotes, things like that). I don't think anyone can tell anyone how to write PHP, because nobody knows how to get it right (myself included). Yet in my many years of coding in PHP, there's been more and more tooling and so-called "standards" that do exactly this.
- timw4mail 6y agoI'm a fan of PHP in general, but I've never liked the FIG coding standards. Common interfaces for logging, caching, and the like are useful, though, so I don't think the PSRs are all useless. After using more languages with a distinction between strings and characters, a string in single quotes starts to look weird. Although there are several questionable "best practices" in general, I have found that stricter typing in PHP has generally been a plus.
- deleted 6y ago[deleted]
- rtheunissen 6y agoIf you look at a language like Go, it's rare to find a project not using the standard gofmt. PSR-12 states that "the benefit of this guide is not in the rules themselves but the sharing of those rules". The guidelines to use single quotes and tabs vs spaces exist for the sake of consistency, to remove that subjective argument from the conversation.
- hparadiz 6y agoIt's just a linting standard. You're free to use it or not and some linters support the entire specification as-is but with tabs instead.
- kijin 6y agoPHP's chaotic developer community, as well as the "there are 1000 ways to do the same thing" philosophy that it inherited from Perl, is fertile ground for those who wish to say that they know better than others. This occurs in every level, from which quote character to use, all the way to how to arrange your namespaces. The PSR's also reflect this tendency. They're a mix of extremely useful standardization (e.g. PSR-4) and hardcode nitpicking about whitespace (e.g. PSR-12). Take what you need, focus on maintainability and interoperability, and ignore the noise.
- anw 6y agoIt's nice to see PHP adding useful things like enums and async (green threads). My foray into Web development started with Perl, but quickly segued into PHP with how much simpler it felt. The ability to hop into vim on your server (or use CPanel back in the day) and edit your site live was exciting back then – but now that very thought makes me shudder with what could go wrong, haha. While I've moved onto JVM languages and Rust professionally, I do hope PHP will continue getting future generations excited about Web development and building out their ideas quickly. FYI: Not sure if the author will see this but some spelling mistakes in the article. [0] E.g. s/reslease/release/ 0. https://stitcher.io/blog/php-in-2021#the-community https://stitcher.io/blog/php-in-2021#the-community
- astrange 6y agoWhat do they want async for? PHP's purpose is to run once to generate one HTTP response - they'd already forgotten this by inventing frameworks, but adding async seems to especially have forgotten this. PHP already had curl_multi_perform which is very useful for running child tasks, but I'm not sure you need much more than that.
- topicseed 6y agoThe usual asynchronous stuff like fetching data from two APIs to then prepare the HTML response to the user. Today, it's sequential, which is fine for DB calls to localhost, but less fine with API calls.
- ifoundthetao 6y agoPeople also use PHP to write backend scripts, without web use at all. While the original and primary purpose may have been for personal home pages, it has evolved considerably since then. Consider an accounting/aggregate billing script for a PHP application that runs on a scheduler. That isn't dependent on the web necessarily, but it does interface with the moving parts of the overall application. Async would be great here.
- francislavoie 6y agoAnother use of async is to build other kinds of servers like websockets, which need to hold long-term connections. ReactPHP + Ratchet works great for that in PHP. Currently it works with an event loop (multiple implementations under the hood, like libev, libuv, etc) similarly to Node. Fibers should make the internals of ReactPHP better, but it'll barely change anything in userland.
- gusbremm 6y agoI wish there was a nodejs equivalent to Laravel
- amilios 6y agoLook into Sails.js -- it's not the same but it's something
- Epskampie 6y agoI would say next.js comes closest for a ‘nodejs server framework’ for me. It’s really great to only use one language for frontend, backend and templating.
- jackbravo 5y agoBut to really come close to laravel I would add something like blitzjs.com or redwoodjs.com. Blitz is built on top of next and adds ORM (Prisma), code generators, even authentication out of the box, so it's really close to Laravel. Redwood is its own thing AFAIK, but also aims to be closer to a full stack framework.
- pgtruesdell 6y agoI'd take a look at Nest.
- mokanfar 6y agoNest.js is more like Angular
- gremlinsinc 5y agoI think you're thinking of Next/Nuxt. I'm a laravel dev but have tried every framework under the sun cause I get bored. Next/Nuxt are basically react/vue SSR / Server Side Rendering or SPA frameworks... which seems more like Angular..no? Nest.js is a fullstack backend framework more like fastify or express and has guides on connecting databases, graphql, etc.... Personally, if I were going to go with node, I'd choose nest.js or feathers or express as they have the best ecosystems ... but none seem as mature as laravel, rails, or django.
- eric4smith 6y agoI know PHP is really great (and always has been). But sh*t, there is soooo much bad, no, really really bad PHP code that lives out there. Isn't it?
- krapp 6y agoSure, but you can say as bad or worse about almost all code in the wild. Almost everything is garbage.
- smitty1e 6y agoSturgeon's Law applies.
- rtheunissen 6y agoYeah, also some incredible literature and worthless spam. Practically infinite expression will inevitably lead to poor results in one corner or another.
- mountainriver 6y agoYeah in my whole career, the worst codebases I’ve worked on are far and away PHP
- deleted 6y ago[deleted]
- gremlinsinc 5y agoHAve you never worked with jQuery / Javascript in <script> tags and no real state management other than Local Storage or maybe some cookies? BEFORE webpack/etc so every plugin/package... is linked from the page you're working on? PHP is bad, but my god some of the javascript nightmares and if you fuck up javascript with some recursion you can crash the entire browser.
- joseluisq 5y agoYeah, same experience for me. Lots of fragile and bloated code bases. And I don't tell you about maintainability nightmare. Javascript in the server is another example. So this is not the fact that PHP people can write useful things with it or that PHP can help them to put food on the table, etc. Here some questions not only for PHP enthusiasts: Are you using the right tool for the job? If so, Are you do it well? Are those programs that you write easy to maintain over the time? Is the language providing you the necessary mechanisms to help you to do so?
- mmckeen 6y agoSo basically PHP is still catching up to Hack and but not quite there yet?
- tyingq 6y agoThat sounds right, but probably at considerably lower cost.
- kijin 6y agoHack might be better from a language design point of view, but most people outside of Facebook seem to have lost interest in it once PHP 7 caught up to it performance-wise.
- nine_k 6y agoWith Hack's extensive static type checking and even contexts / coeffects, it's much more than just performance. The bigger your system grows, the more pain it removes. You still can mix it with plain PHP, much like you can mix TypeScript with plain JavaScript. I wish high-profile PHP projects, like Nextcloud, migrated to Hack eventually; it can be done piecemeal.
- muglug 6y ago> With Hack's extensive static type checking and even contexts / coeffects Have you used contexts/coeffects? My understanding is that it's still yet to be fully rolled out to WWW, and nobody outside FB has yet played around with it. IMO it still has some DX issues (https://github.com/facebook/hhvm/issues/8828 https://github.com/facebook/hhvm/issues/8828) and the examples given in documentation don't actually work in real life (https://github.com/hhvm/user-documentation/issues/1016 https://github.com/hhvm/user-documentation/issues/1016).
- nine_k 5y agoNot extensively; rather, I had to pay attention to the limitations that a particular context enforces. It's definitely a fresh feature, iirc rolled out last winter.
- bouncycastle 6y ago> Still no support for generics, unfortunately Huh? PHP is a dynamic language, you already have them in principle. Usually you can just have no type and use instanceof, but also requiring the parameter to be an interface does the job in most cases if you need more clarity. Edit: There's also method_exists! Also a whole heap of other tools in the toolbox https://www.php.net/manual/en/ref.classobj.php https://www.php.net/manual/en/ref.classobj.php
- muglug 6y agoYou have them in theory — you can use generic concepts to model operations — but that dynamism also allows you to break any generic model that might exist. For example I might say that a function takes a parameter of type "Traversable<string>", but there's nothing stopping me manipulating that object and turning it into a "Traversable<int>" because of that same dynamism. It might be possible in the future to introduce reified generics which could be guaranteed by the engine, though that may end up being too difficult to add and maintain. In the meantime static analysis tools (like Psalm, which I created) are able to model operations using generics described in docblocks, which works pretty well.
- edoceo 5y agoTraits!!
- o_p 6y agoDaily reminder that by Lindy effects, for each additional year of php still alive the probability of staying alive increase. We will probably die before PHP
- ashton314 6y agoBefore you call me a troll, know that I worked with PHP for two+ years maintaining both legacy codebases and writing new code with Laravel. My question is: why would anyone want to start something new with PHP in 2021? Is there anything that it does better than any other language/ecosystem? I feel like the community is full of (but not exclusively composed of—there are some gems like Caleb Porzio who write good stuff) people who just care about hacking something together and, as long as it works, it's fine. They care nothing about elegance and have but a dim conception of larger CS/SE principles. For example, why would you write something in PHP when you've got an excellent choice between Ruby/Rails or Elixir/Phoenix/LiveView, both of which are fantastic, and, especially in the case of the Elixir/Phoenix stack, really developer friendly, easy to set up and deploy, etc. and also have solid foundations? I'm glad to see PHP getting better—it will certainly improve life for those maintaining old PHP projects that are agile enough to upgrade—but I really see no reason to not choose a better tool in this day and age. (You may now call me a troll if you see fit. I stand by what I said though. :-)
- 55555 6y agoPHP is often a good business decision because there is no shortage of affordable devs to help manage the code. If you're building a small, low-margin business, it may be the best choice. I hate writing PHP btw.
- solraph 5y agoFor lost cost Wordpress stuff sure, but for higher end senior type work I think it's worse than other languages. While this is obviously location dependent, over the last year or so I've had dozens of calls from recruiters asking me to come work on PHP (mostly Symfony and Laravel) applications, and telling me they just can't find competent senior and lead devs.
- zoover2020 5y agoYep, resonates with me. At the same time, these jobs pay very little compared to other stacks. Go figure why they can't find people :-)
- genmon 5y agoPHP has astounding longevity. In maintaining my personal websites (static pages, web toys, projects with my writing groups), I always ask myself: how will I keep this running in 20 years? It's unrealistic to think that languages will stay static over 20 years -- servers get rebuilt, old versions languages get deprecated, frameworks disappear. So the question becomes - will I know how to fix or rebuild this, even if I don't touch the code more than once every 5-10 years? - what is sufficiently resilient to mean that "mean time between rebuilds" is as long as possible? Over all that time, what's lasted best are CGIs (Python/Perl) and PHP, running behind Apache. I don't use PHP day-to-day, so changes in the language don't affect me much. But for keeping the history of the web alive, it is an unparalleled tool, and its proven commitment to longevity is why I still reach for it. Separately: I think that longevity is a question we should ask ourselves more about the web. New ideas often come from experiencing old (even failed) ideas -- but if those old ideas just disappear, we lose some of our ability to progress.
- capableweb 5y ago> It's unrealistic to think that languages will stay static over 20 years Depends on the language really. JavaScript? Yeah, good luck even spinning up a year old project on NodeJS without any breakages. Slightly better situation in the browser but most likely you'll need to change something if you're using NPM. On the other hand, Clojure hasn't had a breaking change in their core API in almost 14 years now, since you can change the language yourself without affecting the core API for others, so new features are usually launched as libraries instead of changing the core API. Coming from the JS world, being able to spin up old Clojure projects without having to do any changes is really a undervalued feature of the stability of Clojure.
- zkldi 5y ago> Depends on the language really. JavaScript? Yeah, good luck even spinning up a year old project on NodeJS without any breakages. Slightly better situation in the browser but most likely you'll need to change something if you're using NPM. Is that really true? I can't think of much in terms of older nodeJS stuff that would break on modern node (and with N, you can just install an older version of node).
- brianzelip 5y agoI’m primarily a javascript dev who had to dive into php and wordpress this past year for a client.[0] The php docs often drive me nuts with their range of what info and examples are available per feature, and the language’s naming can be funny at times with a lack of consistency... But I really like it. Php writes and reads like javascript. And working with dates has actually been pretty fun - I like the natural language manipulation layer it provides, ie: `last Sunday`, etc. And the built in url parsing. I’m happy to have added it to my tool belt! [0] https://www.zionbaltimore.org https://www.zionbaltimore.org
- justAnIdea 5y agoThe "annoying" thing about PHP is that every time I try to get away from it and use "proper tools" (e.g. net core) for a project, I'm kinda drawn back to PHP simply because of its unparalled productivity with your average web app creation. No types (typing is the right way to do it, especially with bigger projects and more people, but they slow you down, no question about it), no compilation, great std lib (once you learn it) packagist/composer for things not in the std lib, laravel/symfony for when bigger scaffolding ie needed... and you just blast away, it's one thing implemented after another, and boom, boom, boom, another, another, another. Need to mess with XMLs, JSONs, CSVs, XSLes, PDFs? Just use the std lib or if that's not enough just use one of the packages on packagist. Everything is so fast to put tohether, I can create a same web app in php in about half the time than in .net... yes, the .net version will probably be more robust and less buggy, but who really cares? One you're building a govt. app or a bank app, then you'll care, but until then I just cringe every time I have to do basic modal functionality (load data for the modal from the db, populate modal form with the data, show the modal to the user, validate submitted data, do something with the valid data, save data into the db, show ok status to thr user) in .net a it takes me ages due to all the hoops i have to jump through. The only reason I'm even bothering with .net s because PHP is still seen as a language for novice programmers (it is kinda true, i've seen some horrible coders in my php years), but that's mostly a function of its success and the how easy it is to do many, many things.
- cardanome 5y agoIt is a great language to put food on the table. Especially in Europe it is still the dominant backend language. If you want to have flexibility on where you work it is a good language to know. You have the productivity of a scripting language but still great static analysis tools that help you out. It really fills a sweet spot that no other language does. Yes, Node has Typescript but then you have a super slow compiler negating the scripting language benefits. With PHP I can change a file and see instant results. Also languages like Go make it hard to debug anything on an live server as it is all compiled. PHP code is mostly boring. The coding style tends to be very pragmatic. Even bad beginner code runs great due to dead code elimination and the like. Shared nothing architecture makes understanding and debugging the system so much easier. Hosting is simple and inexpensive. Beginner can just copy their files to an shared hoster and be done with it. PHP is only a bad choice is you have really complex requirement and need a high level of reliability, which most Web projects don't. I think Haskell fills a good niche here. It is really underestimated. Also Elixir if you happen to build anything where you can play out its strength.
- 0xy 5y agoThe elitists who constantly hound on PHP's deficiencies as if developers haven't heard about them for the last 20 years are the same types of people who build a fancy side project that never sees the light of day because it's massively over-engineered in some obscure flavor-of-the-month language. Your customers don't care what's under the hood beyond your ability to provide value to them. If PHP lets you ship faster and get your product in the hands of consumers, it's a good language.
- arp242 5y agoThat a lot of the issues that were "not a problem" in the 5.x days are now addressed in PHP 7 and 8 is evidence that the technical criticism was valid and hardly "elitist". There are many successful projects in many different languages. You're using one of them right now. That claim only PHP devs care about shipping useful products is extremely silly.
- 271828182846 5y ago
- codingclaws 5y agoI like PHP but dislike the PHP frameworks.
- djxfade 5y agoWhy?
- codingclaws 5y agoMost languages have great DX. It seems like the majority of PHP frameworks have very bad DX. I would consider using Laravel or Symfony.
- hunter-2 5y agoI am not a programmer, and I have hired developers to build websites for me for close to 15 years now. I love PHP. Two reasons. One, because this was the language I learned to code when I started off. So, it's easy for me to understand stuff my developers tell me. More importantly, the language is so mainstream that the developers I work with are quite cheap to hire. The more sophisticated a language is, the fewer the programmers available for hire, which shoots up the costs with no visible changes to me on the front-end. I'm currently building a simple search-engine like project - all on PHP. We have been testing it right now, and it's fast and usable - and I am not regretting my decision to use PHP for this; yet.
- knorker 5y ago> All of that to say: PHP is alive and doing very well. Oh. I was hoping for good news. :-(
- keb_ 5y agoI no longer use PHP, but I have to say, I truly appreciate the regular articles on the state of PHP by @brendt_gd. I think they're absolutely awesome, and I wish I could get the same kind of regular rundowns for Python, for example. :)
- Ambix 5y agoI used to work both with Go and PHP. At first when I started digging into Go I thought that eventually I'll replace platform for all my future PHP projects. But it never happened. Every time I should implement business logic and info exchange with database I immediately became frustrated with so much boilerplate code of Golang. In comparison, writing such code in PHP is real breathe. But suddenly I've got used to Go speed and want to get the same benefits for my PHP APIs. So I've implemented my own framework with low latency and hight throughput in mind. It beats many Go frameworks on TechEmpower Benchmarks! Now I feel like I found epiphany finally :) https://github.com/gotzmann/comet https://github.com/gotzmann/comet