top | item 39733172

(no title)

JonathanBeuys | 1 year ago

Even though I prefer Python over PHP, for web projects, I'm probably down with PHP forever. Because it so nicely supports stateless request handling without long running processes.

In PHP, you can just throw a php file on a webserver and it works. To update, you just update the file. You don't have to restart anything.

On the dev machine, you can just have Vim in one window and Firefox in the other, change code, hit F5, and you see what you did.

I don't like having to run a code watching process which then recompiles the whole codebase every time I save a file.

discuss

order

hiAndrewQuinn|1 year ago

PHP is underrated, especially as a learning resource. I'm very surprised I only ever built something with vanilla PHP on the job a few months ago - and how fast I could go from idea to prototype.

There is a very natural learning progression to: First build apps that run purely locally; then build a few static websites, maybe starting with hand-crafted HTML and eventually using something like Hugo; then build a small dynamic website with vanilla PHP; then finally build something with a more complex framework, like Laravel or Django. Going upwards in these iterations I think would help a lot ofd newer devs internalize where the tradeoffs of inital complexity vs. future ease of development lands for them.

devnonymous|1 year ago

The differences you speak about arise due to the nature of their design. PHP was created for the web whereas web programming support in python wasn't part of the language design. When you speak about web programming in python, the seam between the language and the web is usually a wsgi/agsi layer. This is where all the things you mentioned come into play. There's a whole lot of benefit imo to using python over php beyond that seam.

nijave|1 year ago

There's a fair bit of nuance and it really depends on the setup. You can run Python with CGI and execute once per request but it's much more common to use wsgi/asgi. Likewise, I think php-fpm is still pretty common which runs long running PHP processes.

saddist0|1 year ago

The difference is striking the balance between developer's speed and performance. In case we don't want to reload everything and run from scratch, it's pretty easy to do with python too. But we "chose" to run it always and quick reload, so the requests aren't too slow [and scalable].

Rest of the things you mentioned are pretty same for Python as well.

JonathanBeuys|1 year ago

You talk about performance, but I think that is another point for PHP. In my experience, PHP handles the same requests faster.

Yes, I could build everything from scratch myself in Python and have the same statelessnes as in PHP. But parsing headers, creating headers etc feels like it should be handled by a framework. In PHP, it is build right in.

And if I would build it, it would talk to the webserver via CGI. But I think CGI is slow. For PHP, you have mod-php which is super fast.

fulafel|1 year ago

If PHP doesn't recompile your script imports, how does the reload tracking work with dependencies? Or does it punt somehow (eg only reloads your script but not is imports)?

There are various implementations of this kind of autoreload system for Python but it always seems to come with compromises on semantics (different initialization order causes behaviour differences).

smashed|1 year ago

Most major PHP frameworks like laravel, symfony, Drupal, Magento develops all kinds of complex caching layers to work around PHP's stateless 1 request/1 execution model, essentially poorly recreating shared application state you would get for free with a long running worker process.

Python's import model is not without its flaws either, but at least you have a working application state, no need to fully initialize your app for every single request.

For simple apps that are contained within a few files, PHP is hard to beat for simplicity and speed.

JonathanBeuys|1 year ago

Imports are also updated the moment you update the imported file.

I'm not sure if PHP stores any compiled binary or byte-code at all. Maybe it compiles it all on each request. It's super fast though, even with tons of imports.

My guess would be that it keeps compiled versions of each file in memory and on each request, it walks down the whole import path. And when it encounters a changed import, it compiles only that one.

Would be cool if someone with more knowledge could shed a light on what is actually happening.

raziel2p|1 year ago

In PHP, dependencies are just .php files just like your own code, it all works the same.

PHP code is also typically far less complex than Python modules - modern PHP code consists of a single index.php with procedural code, and everything else is just class / function definitions, so there are no side effects.

alecsm|1 year ago

If you're talking about importing third party dependencies, composer takes care of that.

raverbashing|1 year ago

You can just do this with Flask or other frameworks/servers that support auto-restart

(yes I think some js frameworks also allow this)

JonathanBeuys|1 year ago

When a framework "supports auto-restart", that usually means it has its own webserver for development and the auto-restart is supported when you use that.

I don't like having a different webserver in development and production.