News for hackers. Stuff that matters.
Re:PHP is worth learning and using by Klathmon on Thursday November 18, 2021 @07:11AM (#29264542)
My favorite thing about PHP is the execution model. Every single request is brand new and runs the whole program start to finish.

IMO that's extremely powerful in its simplicity and while you can get it in other languages, it feels like like a "core competency" for PHP (just like how async code is easier in javascript than in python, because JS kind of had it from day 1)

Re:PHP is worth learning and using by boudin on Thursday November 18, 2021 @07:22AM (#29264613)
I see this as the opposite and find it adds quite a load of complexity and prevent to do some form of optimization in an app that has its own server.

It adds its load of complexity on how to run the apps itself, you need an external server, apps often requiring some customization of the server that will run it (either mod-php or php-fpm). It means that parts of our app settings lives outside of the app, it also make updating php itself quite annoying.

Re:PHP is worth learning and using by tlackemann on Thursday November 18, 2021 @08:24AM (#29265078)
I don't find this to be true at all.

> you need an external server

Spoiler, you need an external server for everything on the web; you've just been brainwashed to think serverless is actually that.

Re:PHP is worth learning and using by boudin on Thursday November 18, 2021 @12:26PM (#29267996)
What are you talking about?

Lots of languages and frameworks make it easy to be self-hosted with there own server. In Python, .net, Go, Rust this is quite common.

This means that your app can be a self-contained app + server and the server part can have some business logic as well.

With Go, .net, Rust apps (and potentially others) that's quite nice to be able to produce a single binary app that you can just run anywhere without installing any framework or setting up any external server and it's ready to listen to incoming queries.

That can even be a good enough setup for home things that are not exposed to the web and where setting up reverse proxies could be overkill.

Re:PHP is worth learning and using by __MatrixMan__ on Thursday November 18, 2021 @09:33AM (#29265824)
Good point, but just to nitpick: I think that ipfs-js let's your external server be a process in someone else's browser, which is about as unserverlike as servers get.
Re:PHP is worth learning and using by thecatspaw on Thursday November 18, 2021 @08:27AM (#29265102)
You do not need an _external_ server for a lot of languages. If you use node for example you can use the express package to run a custom server, or embedded tomcat for java
Re:PHP is worth learning and using by tlackemann on Thursday November 18, 2021 @08:30AM (#29265135)
I suppose, but I've never encountered a production site that was using Gunicorn or similar as a true server. Usually that's coupled with something like Nginx or HAProxy.

So yeah, you technically don't need one for Ruby or Node.js, but I sure would.

Re:PHP is worth learning and using by redm on Thursday November 18, 2021 @08:51AM (#29265307)
PHP has a built in web server you can launch from the CLI and run the script. `php -S <address:port>`
Re:PHP is worth learning and using by fooyc on Thursday November 18, 2021 @09:49AM (#29266005)
The kind of optimizations you would do in an application server would prevent you from scaling pass a single server
Re:PHP is worth learning and using by timw4mail on Thursday November 18, 2021 @09:13AM (#29265574)
PHP does have it's own built-in server as well, although it is not really meant for production use.

Global PHP configuration options have become less important over time, with resource limits and extensions being most of what has to be configured now.

Re:PHP is worth learning and using by boudin on Thursday November 18, 2021 @12:30PM (#29268047)
My bad, I didn't know that about PHP build in server

I only host one PHP app now (Nextcloud) and it has definitely been a bit of a pain in comparison with other things I self host.

Re:PHP is worth learning and using by timw4mail on Friday November 19, 2021 @10:35AM (#29278219)
Nextcloud is more complex than most PHP apps.
Re:PHP is worth learning and using by fooyc on Thursday November 18, 2021 @09:56AM (#29266102)
Async code is a good way to achieve some level for performance in I/O bound workloads, but it's a pain for the programmer. Because of that I wouldn't say that it's necessarily a good thing that JS is async-first.

In my opinion, high level languages should not expose async primitives to the programmer - this should be abstracted away by the language and its runtime. Go is doing this (all I/O is async under the hood), and it's awesome: You can write synchronous/sequential code and get the performances of async. I would love if other languages copied that.

Re:PHP is worth learning and using by Klathmon on Thursday November 18, 2021 @04:21PM (#29270739)
>In my opinion, high level languages should not expose async primitives to the programmer

Just another reason why the "each request gets a process" architecture can work well. You generally don't need to worry about async stuff in PHP, because your request has the whole process to itself.

Re:PHP is worth learning and using by afiori on Thursday November 18, 2021 @12:23PM (#29267947)
Before being async as in async/await Javascript was also async as in having an external event loop and being event driven.
Re:PHP is worth learning and using by fooyc on Thursday November 18, 2021 @06:14PM (#29271831)
Yup. Go too, but the programmer doesn't need to know it.
Re:PHP is worth learning and using by defanor on Thursday November 18, 2021 @08:02AM (#29264921)
That's not quite a language feature though: one can write (Fast)CGI or similar programs in any common language.
Re:PHP is worth learning and using by chippiewill on Thursday November 18, 2021 @08:27AM (#29265103)
I've never actually tried writing CGI scripts with a non-PHP language (I've not really seen the point since it's usually more ergonomic to just use a language native-server interface like Python's WSGI).

Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level? (getting the performance benefits of a persistent process, while having the simplicity of CGI-style execution).

Re:PHP is worth learning and using by tyingq on Thursday November 18, 2021 @08:59AM (#29265420)
>Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level?

I know that's how the TCL and Perl FastCGI implementations work. I suspect that's how most of them work, and there's lots of languages supported by FastCGI.

Re:PHP is worth learning and using by defanor on Thursday November 18, 2021 @09:00AM (#29265421)
> Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level?

I'm not aware of other languages where it is baked into a language itself, but FastCGI libraries tend to be basically drop-in replacements for CGI ones (at least it's the case with common C, Perl, and Haskell libraries; sometimes CGI and FastCGI libraries are combined, so that they are usable in either setting): you get the optimization, while still can pretend that it's a regular CGI. I guess the primary difference from PHP is just that global/static variables would survive.

Re:PHP is worth learning and using by resonious on Thursday November 18, 2021 @07:20AM (#29264593)
Forgive me for going a little off topic here but is it really true that JS was async-friendly from day 1? When I started using JS seriously 8 years ago, async code was horrible (callback hell, etc.) The web standards guys retrofitted native async way after the matter.
Re:PHP is worth learning and using by kall on Thursday November 18, 2021 @08:09AM (#29264970)
Doesn‘t this more or less mean "the only execution environment is event based, has a run loop outside of your control and calls your code whenever it wants" and "there is no busy sleep". So it was callback based from day one. Is that the same as async? I think it is?
Re:PHP is worth learning and using by resonious on Thursday November 18, 2021 @10:50AM (#29266790)
That makes sense, thanks! It has indeed been run in a loop from the start despite the poor ergonomics - I did not think of it in that light.
Re:PHP is worth learning and using by tylergetsay on Thursday November 18, 2021 @07:44AM (#29264768)
async/await is just syntax sugar around promises which are a just a nice way of organizing callbacks, so yes I'd say it's true.
Re:PHP is worth learning and using by nkozyra on Thursday November 18, 2021 @07:45AM (#29264779)
Probably more accurate to say it was async from day one. Which people probably realized the first time they had to deal with setTimeout

The original promises syntax and chaining in ES6 were not particularly user friendly.

Re:PHP is worth learning and using by TheCoelacanth on Thursday November 18, 2021 @02:44PM (#29269523)
Isn't that exactly the same as most web frameworks except without a few lines of code saying something like "when this URL is accessed, run this function to handle it"?