What are the "modern" features of php? It looks like it's trying to shed it's dynamic nature and add types (with annotations etc). Also frameworks like Symfony / Laravel look more and more like java web frameworks to me.
I'm not saying this is necessarily bad but there's nothing modern about types. Also, might make more sense to choose java if you need types.
The biggest advantages of PHP over Java are build and deploy times, so coding a php app is much more rapid. You can test your app right away, even after a single line change and get immediate feedback on the screen, which I think is important in web dev because a lot of it is visual.
The other advantage is the run-time. Java has a slow startup time and when you redeploy then you need to stop/start your entire app. With php you can fix / update one part of your app without the need for a server restart.
Another advantage is that php runs each request with a clean state, that means all the variables get destroyed after the request, helping to avoiding memory leaks, and possibly issues with concurrency which Java exposes. Types are great, but sometimes they can get in the way too and slow you down, (I still haven't figured out what those <funny> types mean). In all, development in PHP is so much faster and easier over Java.
Yeah sure, no need for state in a CRUD API. But while it is the most common use case for PHP applications (well actually for application written in scripting languages working with http servers), it's not the only use case.
When the only place where you can put state is the database then every piece of state is written in the database. Which lead to intelligent individuals (no pun/offense intended) to write clever piece of infra such as Redis. The truth is, for 10 Redis deployment there's 7 (8? 6? Well, a substantial part) where a long living process holding little state would have done the trick. Now you need to deploy, maintain and scale Redis too.
Yeah, but having to use Redis is a must for any web app/API that grows. So all PHP is doing here is forcing you to adhere to best practices of shared-nothing architectures early on.
Session variables are tied to user sessions (like name suggests), so they cannot be used to persist application state (e.g. cached content, compiled templates, metrics, etc.)
I see downvotes on my GP post, I'm simply stating the fact: if you need state for a building a powerful webapp then obviously there's better runtimes that PHP+Apache, I don't see how one could disagree with that statement, apart from not having sufficient experience in that matter.
There's plenty of good reasons to counterbalance that fact thought, PHP has a very good ecosystem, multiple mature/powerful web frameworks, and cheap/abundant workforce. But it lacks a state holding runtime and for the most demanding applications it's a sufficiently big technical hassle to encourage seeking other runtime and/or language.
Recently did some nodejs work. It was surprisingly fun. There are A LOT of sharp edges, but working "closer to the metal" is great. Fast deploy and startup is GREAT.
Am an early, vocal Java partisan. Java world HTTP servers fell into a ditch and kept digging. Servlets and JSP weren't too bad. Wasn't crazy about Tomcat or NetSuite, but ok. Then it just got more and more nutty. J2EE, Spring, XML, schemas, annotations, etc.
There's nothing about Java that rules out simple and quick. For medical records stuff, I replaced a huge J2EE/BizTalk style backend with stupid simple process runner for stupid simple tasks. Think Windows OS Task Manager running AWS Lambdas.
In conclusion, I remain sad about the enterprisey detour Java took.
> Another advantage is that php runs each request with a clean state, that means all the variables get destroyed after the request, helping to avoiding memory leaks, and possibly issues with concurrency which Java exposes
Care to elaborate? How is that different than java web frameworks?
In a Java web framework, your classes have static fields, so user code or any library can assign values to them.
Language support for a request being ephemeral is far more effective than frameworks proposing it as a good practice.
And everyone working on PHP libraries in C know what a request is and that it ought to be ephemeral, so even outside the core language there's a clearer understanding.
For one step beyond edit/save/refresh try repl development in Clojure where you get the benefits of the JVM without the startup penalty. After the initial boot, that is.
> Also, might make more sense to choose java if you need types.
Java is not a replacement for "PHP with types". There is currently nothing you can deploy as easily as a PHP web app. The operational overhead is very low because cheap, robust hosting providers have decades of experience with the most typical LAMP style stack.
I would also disagree in terms of language features. Gradual typing through type hints (and other 'on demand'-style consistency features) is a very ergonomic way to introduce consistency during development (plus implied performance optimizations). You write in 'free-dynamic-mode' initially and then add type hints where they make sense bit by bit, typically in function signatures. There are many examples of this in the (semi?) dynamic world.
You couldn't be more wrong about the ease of deployment.
PHP is one of the hardest things to deploy. You need at least a web server and a process manager. Most popular choices are nginx + PHP-FPM or Apache + libapache2-mod-php.
You also need to learn how to properly configure both of them, since both have like a million options, and default installation doesn't work in a lot of cases (e.g. uploading of files larger than a few MB).
If you don't want to use libapache2-mod-php, you will have to figure out how to deploy two different services, which makes things difficult in a Docker environment.
---
As opposite to that, deployment story with Go, Rust, and similar compiled-to-a-single-binary languages, is a lot easier. Just drop the binary to a server or add it to a Docker container.
Many smaller PHP web sites are deployed on VPSes and managed with CPanel or Plesk control panels. None of what you describe is necessary. The web server is pre-configured and PHP settings can be easily changed. Even setting up PHP on Ubuntu or CentOS is a 5 minute job. Tweaking configuration settings for max upload, max post size, etc. are very common and well understood.
Once everything is in place, most deployments are as simple as copying the new build over and changing a symlink. No process restarts, nothing.
"Easy to deploy" and "Many cheap webhosts are already configured for it" are still very different things. I never found it helpful to conflate them. For example, a VPS with CPanel/Plesk is quite the dependency. As is "a cheap PHP webhost with servers configured for your PHP scripts".
I look at it this way: PHP apps are so easy to deploy, it's a commodity. I run my own dev servers then move them to VPSes, billed to the client, for deployment.
Seconded. I was left scratching my head for a long time trying to work out why php-fpm, when reloaded via systemctl on CentOS 7, was not setting-up /var/run/php-fpm.sock with the correct ownership. I eventually had to write a shell script to resolve the issue. The version of php-fpm in question, by the way, was a more up-to-date version than the CentOS 7 default. Anyway, that's just one example of how mdoern PHP deployments differ from the over-hyped static deploys of yesteryear where you just FTP a bunch of .php files into your DocumentRoot.
Dart is another example. Not exactly Java but certainly built in its likeness. What is it with aping Java's verbosity which, to many, is an embarrassment?
Symfony is directly inspired by Spring, and Laravel is an based on Symfony, so yes, that's the direction they are going.
I kinda hate that trend, but it satisfies a cross section of devs who want "serious" enterprise looking code base but don't want to move from PHP. It's still noticeably different from Java, even with the heavy typing and all the inspiration.