Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

These days, I am super torn about what language to use for new web projects.

PHP:

    - Easy to deploy: Upload files, done.
    - Easy to develop: Reload page, see changes.
    - Lots of HTTP tooling built in.
    - Fast.
Python:

    - Great language.
    - Great code reuse system: Modules.
    - Nice framework: Django.
    - Less breaking changes in recent years.


PHP has a rather nice type system. It also doesn't use whitespace as syntax, which makes it much easier to generate ad hoc.

Slim is a pretty nice framework: https://www.slimframework.com/


Does anyone really FTP files like its 2003? Even in PHP you deploy with some sort of tool, like docker etc. The reload page thing is pretty much solved in all languages with a watcher. entr is a universal one, thats written in C and fast as anything.

The thing (most) other languages have is unicode support and concurrency. In PHP there is basically none of these.

Fast? You mean fast as in CPU bound tasks? 99.99% of PHP code is slow because of IO, and without any concurrency all the other languages beat PHP easily. If you need CPU bound work, you would not pick PHP (or any other scripting language) anyway.

In most benchmarks PHP (with Laravel/Symfony) is barely doing 500req/sec. Compare this to languages in the same space (like nodejs/python) and they run the same program and can serve 10K-30K req/sec.

Having said that python (a slow langauge) is still capable of doing heavy CPU bound tasks with libraries like numpy. Im not aware if PHP can install C dependencies with composer, like you can with pip.



Seems like that requires some sort of ad-hoc PHP extension. These are not in the standard PHP distribution? I would not want to rely on some random PHP extension that maintained by a single guy for anything production grade. Compare that to something like tensorflow thats backed by a HUGE community of maintainers.


Link those benchmarks please. Both 500 and 10k-30k seem extremely low.


That was a ballpark estimation, and while pure req/sec is usually irrelevant, it still comes in when the load starts to increase and you need to squeeze every last drop of perf.

PHP usually is doing poorly, even with its "cache", and when you realize that PHP devs actually are not PHP devs, but framework (like laravel/symfony) devs you need to account for the overhead of the framework too.

But you can have a look at the framework benchmarks game:

https://www.techempower.com/benchmarks/#section=data-r21&hw=...


I think they'd prefer not to be confused with the benchmarks game ;-)

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...


> Reload page, see changes.

This should work in Python, too. With Django, I think you need to use https://pypi.org/project/django-browser-reload/, and rith most other frameworks / WSGI servers just try adding --reload flag.

Edit: Django should wor out of rhe box actually – that package is for refreshing the page in browser.

> Easy to deploy. Upload files, done.

I can see the appeal, but generally you’d want to avoid that (for anything other than quick prototypes, maybe). Set up a CI, push to deploy. This goes for modern PHP as well.

If you want something simple to deploy webapps and know a little Docker, I’ve built a deployment tool you can run on your own VPS: https://lunni.dev/. (Feel free to reach out if you need any help!)


There are of course ways to get "reload page, see results" to work even with Python. After all, computers are touring complete.

But in PHP you have it out of the box. Faster, with less complexity and less resource consumption. And you can use the same setup in development as you can use in production.


Maybe I'm missing something, but PHP is not more efficient in that regard.

When you load a Python page, it is served by an in-memory process. If code is updated, the process is restarted, parsing the code and initialising the application, but it is done only once.

When you load a PHP page, it parses the code and initializes the app for each request. It then tears everything down after the request. There are less wasteful ways (most recent are app servers, just like in Python or other langs), but I'm not sure if those are widely used in local development. Even then, it’s same as Python, Node or pretty much anything else.

And of course, I’m not trying to diss on PHP here – it’s gotten pretty good recently. But reload on change is built in pretty much every app framework nowadays. It works out of the box and is negligibly fast. It’s not a good point to compare.


> When you load a PHP page, it parses the code and initializes the app for each request. It then tears everything down after the request. There are less wasteful ways (most recent are app servers, just like in Python or other langs), but I'm not sure if those are widely used in local development.

There are things like opcode caches that make PHP more efficient transparently, while still feeling to the developer like a reload each time.

There are reliability and development advantages to starting each request from scratch. NO leaks, no state you need worry about.

PHP is very much like serverless.


In my experience:

PHP is always blazing fast, with no additional setup to make "Reload page, see results" work.

Python needs additional setup. Either by monitoring the filesystem and pessimistically recompiling the application every time a file changes. Causing resource consumption every time you hit save in your editor. Or by having the web workers that serve the requests die after 1s of inactivity or so. Which makes the next pageview slow again, even if no code changed.

I think PHP's advantage is because of 3 things:

1: Recompiling changed files is built in.

2: With PHP you can set your project up in a way that only the code necessary to answer a single request is updated. With Python and Django, all the code for all requests is updated and even code paths that are actually never used.

3: PHP keeps each file compiled to bytecode in memory and only recompiles files that have been changed. Although you might accomplish something similar in Python if you let it pollute your filesystem with cached bytecode files.


This is true when you call PHP using CGI or CLI. Then opcode is build, running and thrown away.

But when u are using FCGI or PHP-FPM then you have running process where opcode is cached except on first request where opcode cache is build.


With standard opcaching and jit enabled, the reparsing step doesn’t happen.

Initializes for each request is standard with php-fpm, but swoole/workerman/etc are rapidly gaining popularity and run as a more typical app server with coroutines.


Don't forget Laravel for PHP.


To get to know Laravel, I forced myself to build a project with it for a few weeks and I did not like it.

I found myself getting sucked in into a complex project structure and dealing with all kinds of strangeness like "artisan commands", "the autoload cache" etc.

With Django, I can build a web application in a single file that has "import django" on top and take it from there:

https://news.ycombinator.com/item?id=40788329



Laravel is excellent for building a website, for smaller projects there are simpler tools and frameworks


I much prefer Symfony, but that's mainly because it's the framework I started with.


I was forced to move from Symfony to Laravel and I really dislike it. This experience seems to be very common.


I had hoped to forget


You don't like magic? /s


It’s difficult for me to trust a framework backed by venture capital (https://blog.laravel.com/accel-invests-57m-into-laravel). There are too many incentives to prioritize making money, which makes it easy to overlook developer experience. I rather use Symfony instead.


Symfony took venture capital years ago, it's no different really: https://www.sourceguardian.com/blog-symfony-gets-boost-from-...


> Easy to deploy: Upload files, done

I know people love to say this, but does anyone realistically make websites or web apps that way? No, not really. Even with PHP there are frameworks, there is a package manager, there is version control, and there are deployment systems.

Pretending that PHP developers are uploading a .php file to a shared hosting server (like in 2002) to suit the narrative feels disingenuous to me as it doesn’t align with what I see PHP developers doing at all.


> I know people love to say this, but does anyone realistically make websites or web apps that way?

In PHP, I do. In other platforms, no. My personal PHP site is published by a git push to the server.


I do it all the time, thank you very much. For a simple web app I don't even need a framework - you can literally create a simple files/folder structure, include files, include folders and get stuff done. An yeah, you can also upload the files by FTP. For something more complicated I'd use WP or Code Igniter depending on the specific project. And then you can again just SFTP those files to the server.


That only works if your application has reasonably few users. Otherwise, your upload will result in some requests hitting a partially completed code base overwrite, that is, only some of your changes have been uploaded at request time, possibly leading to an error. This is a nice strategy for a hobby project, but it plain does not work for a business.


That's not true. For mission-critical apps we route the traffic to the stable version while uploading the new version. This may be similar to what most CI tools do but it doesn't change the fact that we just upload the files and can do it as we see fit. Another good solution is to simply switch off a feature for maintenance while uploading it's files. If your software is well planned, that's a breeze and still keeps the whole process very simple.


Well, you’re shifting the goal posts. The original scenario was simply uploading files to the application folder on production servers and reloading the page.

Of course there are viable strategies to avoid this specific issue, but they all introduce complexity of themselves.


>but does anyone realistically make websites or web apps that way?

You are correct in that a lot of PHP use now is larger frameworks with asset compilation and cache clearing etc, but even when developing on large systems like that it is nice to sometimes be able to just manually tweak a file and refresh.

For R&D and quick tests, just uploading a quick & dirty php file to the server is a very useful language feature to have IMO.


> For R&D and quick tests it is a very useful language feature to have IMO

Right, but unless you have an ftp server or quick ssh access and PHP isn’t doing any code caching that feature isn’t an advantage, how many developers are in that situation? Is this something you do?

If you’re running locally PHP spawns its own server which other runtimes have. If you’re running this on a server you’re most likely going to have app/code caching (apc Or opcache) switched on so you’ll need to restart the server anyway, in which case it’s not more advantageous than uploading a js file and restarting node.


> Right, but unless you have an ftp server or quick ssh access

These days all of that is built right into IDEs

> Is this something you do?

Yes. After linking my IDE to a remote location I can then noodle around with scripts to test whatever. The immediate nature of PHP means the instant you hit ctrl-s your changes are live online.

> If you’re running this on a server you’re most likely going to have app/code caching (apc Or opcache) switched on so you’ll need to restart the server anyway

In prod yes, but in dev environments all that is switched off as its not needed.


.. and as soon as you stop just uploading files (which, as you say, nobody does), a lot of the other advantages go away also. Laravel and Symphony both make PHP much slower. If you are going to have sane routing, you're probably going to need to tweak your websever to behave, well, less like a web server. There's a decent chance you'll need to clear a cache after you upload your changed files if you want to actually see those changes.

I actually like PHP a lot, and it's amazing how far it has come in the past 10 or so years, I just think way too many people assume you get the 2004-era PHP simplicity with all of the 2024-era PHP refinements, and you really don't. There's tradeoffs.


Python’s packaging and dependencies system is lacking, but trying to get better. But too many choices not always compatible nor working perfectly right (should you use pip, poetry or pipenv? Well, you see…)

How’s php’s?


They just added extension support to packagist, so composer looks like a pretty healthy ecosystem that's officially supported.

https://thephp.foundation/blog/2024/11/19/pie-pre-release/


> Python’s packaging and dependencies system is lacking

It is? I never had problems with poetry. Though I agree that there are mroe options than necessary.


That's a wild perspective.

Python has the worst packaging ecosystem i've ever seen


worse than javascript?


Python's packaging system is worse, but Javascripts packages / standard libraries are far worse than Python.

In python managing packages is a pain and there are too many package manager options, but for the most part there are good libraries, and chances are you don't even need one because the standard libraries are so good and mature.

In Javascript NPM is really all you need (even if yarn is a bit nicer), but you're gonna need to install 50 packages just to get a basic boiler plate app going and the quality of said packages is not always great.


Node: - easy to deploy: If you dont complicate yourself, with cpanel or plesk hosting is just matter of copy the files. - Terabytes of npm packages (even too much :)) - A non bloated and nice language (JavaScript) - Optional type checking with typescript if you want. - Non blocking IO


> - Easy to deploy: Upload files, done.

Sure, it works for simple/less important cases. But it also means that your application code is inconsistent while the files are uploading.

Stop your service, upload the files, start the service: safer.

For a Django app you would upload files and ask Gunicorn to graceful reload... similar, just cleaner.


Most PHP apps use a deployment method where a symlink gets set to a directory with a new version of the code. Because of how opcache works this has no impact on running requests, while new requests get handled with the new code.


Yes, my point really... it's really not "just upload files" like it's 1997.


That sounds pretty neat.


You can use the same strategy with PHP. Preload all your scripts in opcache. Once you're done making changes, reset your opcache.

In practice, any serious project is likely to be version-controlled. Git pull is generally fast enough that it behaves like an atomic change. (By default, opcache will not reload a file that's less than 2 seconds old.)


I'm pretty sure many PHP dev don't know about OPCache. Many of my colleagues don't know for sure. My point is "be aware of the state of your app code and what you execute", and so be aware of the shortcomings of this deployment "strategy". It's sure perfectly fine and easy for small apps / low traffic / not critical apps. I just want to point that it's not inherently good enough and definitely not the universal way to deploy a PHP app.

Git pull to deploy is something I avoid.


Yeah, I've seen cases where even git is not fast enough. That's when opcache preload comes into play. It's still better than manually uploading files over FTP.

Having said that, the "most modern" deployment strategy is to spin up a new container with your new code already loaded, point your LB at the new container, and scrap the old container. No opcache issues. No race condition.


The PHP framework slim is x1000 better than Django and is quite popular.

https://www.slimframework.com/


technically you can do the same thing with python, via python server pages =)


PHP fast? Compared to all popular web frameworks it's quite low in the pecking order when it comes to performance.


Not sure where you got that from. It’s equally if not faster then python, faster then Java, slower then compiled language, faster then ruby. Loses to NodeJS most of the time.

But who cares, we are literally talking millisecond differences between them all. Throw a reverse proxy, DB into the mix and a few packages and they are all slow.


And if we actually want to talk speed, PHP with something like Swoole or ReactPHP is many times even faster[0] than the already fast regular PHP.

[0]: https://medium.com/@dimdev/9-php-runtimes-performance-benchm...


> faster then Java

You sure about that? Not what I would have expected. Source?


My point was less about the leaderboards and more about it being pointless comparison. But I was looking at https://web-frameworks-benchmark.netlify.app/result?l=java,p... though I don't really know what people consider "best benchmark" for raw vs raw. Once you start throwing in apache/nginx/proxies/what ever it really starts to balance itself.



Definitely not faster than Java if we're talking single thread performance.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: