5 ms·
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
by mg 2y ago
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.
- aedis 2y agoDon't forget Laravel for PHP.
- orangepanda 2y agoI had hoped to forget
- BafS 2y agoYou don't like magic? /s
- mg 2y agoTo 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 https://news.ycombinator.com/item?id=40788329
- conradfr 2y agoYou can do that with Symfony. https://symfony.com/doc/current/configuration/micro_kernel_trait.html https://symfony.com/doc/current/configuration/micro_kernel_t... https://symfony.com/blog/new-in-symfony-7-2-simpler-single-file-symfony-applications https://symfony.com/blog/new-in-symfony-7-2-simpler-single-f...
- jonwinstanley 2y agoLaravel is excellent for building a website, for smaller projects there are simpler tools and frameworks
- ognarb 2y agoI much prefer Symfony, but that's mainly because it's the framework I started with.
- bojan 2y agoI was forced to move from Symfony to Laravel and I really dislike it. This experience seems to be very common.
- donperignon 2y agoIt’s difficult for me to trust a framework backed by venture capital (https://blog.laravel.com/accel-invests-57m-into-laravel 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.
- esskay 2y agoSymfony took venture capital years ago, it's no different really: https://www.sourceguardian.com/blog-symfony-gets-boost-from-sensiolabs-funding-post-152-1.html https://www.sourceguardian.com/blog-symfony-gets-boost-from-...
- notpushkin 2y ago> 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/ 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/ https://lunni.dev/. (Feel free to reach out if you need any help!)
- mg 2y agoThere 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.
- notpushkin 2y agoMaybe 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.
- mg 2y agoIn 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.
- alternatex 2y agoPHP fast? Compared to all popular web frameworks it's quite low in the pecking order when it comes to performance.
- dubcanada 2y agoNot 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.
- askonomm 2y agoAnd 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-benchmark-cbc0527b9df9 https://medium.com/@dimdev/9-php-runtimes-performance-benchm...
- biorach 2y ago> faster then Java You sure about that? Not what I would have expected. Source?
- dubcanada 2y agoMy 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,php 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.
- igouy 2y ago> equally if not faster then python https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python3-php.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... > faster then Java https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/java-php.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... > faster then ruby https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/ruby-php.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- JodieBenitez 2y ago> - 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.
- kijin 2y agoYou 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.)
- JodieBenitez 2y agoI'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.
- kijin 2y agoYeah, 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.
- lenlorijn 2y agoMost 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.
- jiehong 2y agoPython’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?
- BadBadJellyBean 2y ago> 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.
- sigmonsays 2y agoThat's a wild perspective. Python has the worst packaging ecosystem i've ever seen
- taskforcegemini 2y agoworse than javascript?
- steve918 2y agoPython'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.
- pluc 2y agoThey 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/ https://thephp.foundation/blog/2024/11/19/pie-pre-release/
- jayflux 2y ago> 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.
- sjm-lbm 2y ago.. 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.
- alt227 2y ago>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.
- jayflux 2y ago> 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.
- cess11 2y agoPHP 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/ https://www.slimframework.com/
- whalesalad 2y agotechnically you can do the same thing with python, via python server pages =)
- deleted 2y ago[deleted]
- fbn79 2y agoNode: - 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
- ransom1538 2y agoThe PHP framework slim is x1000 better than Django and is quite popular. https://www.slimframework.com/ https://www.slimframework.com/
- shikck200 2y agoDoes 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.
- Implicated 2y agoSir, PHP can fly. - https://www.php.net/manual/en/book.ffi.php https://www.php.net/manual/en/book.ffi.php While I'm at it: - https://pecl.php.net/package/tensor https://pecl.php.net/package/tensor - https://rubixml.com/ https://rubixml.com/ - https://github.com/RubixML/Tensor https://github.com/RubixML/Tensor
- shikck200 2y agoSeems 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.
- Kiro 2y agoLink those benchmarks please. Both 500 and 10k-30k seem extremely low.
- shikck200 2y agoThat 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=ph&test=db&l=zijlof-cn3&f=zik0z3-zik073-zik0zj-zik0zj-zik0zj-zik0zj-zik0zj-ziime7-zik0zj-zhxjwf-zik0zj-zik0zj-zik0zj-zik0zj-1ekf&p=0-0-0-e8-13ydj4-0 https://www.techempower.com/benchmarks/#section=data-r21&hw=...