"How do I make a web page talk to a database?"
I'd say: Well, you know that HTML file? Rename it to become a PHP file and you're almost there!
As pretty much all cheap hosting already offers support for PHP (and MySQL for that matter) this would almost always work.
I would love to be able to do this with NodeJS, but imagine teaching that to an absolute beginner. The conversation would have to begin with hosting platforms / SSH / server management / reverse proxies etc....
In a similar fashion, I abstracted away the database connection, query and returning of results into one lazy-inited function, so talking to the database really was just like
<?=q("select name from users where id = $userid") ?>
I worked a lot with other languages, none feeling as natural to me as this one, aside from Ruby.PHP's parameterization features in PDO can be abstracted so you can turn this into:
$vars = array(":userid" => $userid);
q("select name from users where id = :userid", $vars);
It's still pretty concise and is much safer.[0]: as in, I would have nightmares trying to introduce beginners to full JS stack vs I would have nightmares thinking what they will end up coding when they easily become dangerous with PHP (which is I guess why there are so many bad PHP codebases: it's super easy to start)
Will never understand why some people find that so offensive and will tell you that you mustn't use it or imply that you are ignorant or stupid for using it.
I think JS can be worse. There are things that are possible with dynamic languages that are literally impossible with static ones.
So think of PHP less as a "bad language" and more of a code smell.
Requesting `index.php?something=X` implied `$something = "X";` in the global scope at the beginning of "index.php". And since the global scope was not limited to a file, tracing a variable through files and side effects was a nightmare. Even understanding the code intent was often hard!
Before PHP7, there were many elements of the language that were meant to simplify its usage, but had awful consequences in many cases. Even more because it bent the PHP community toward a quick and dirty process. "Magic quotes", the automatic escaping was one of those abominations. For any request input (e.g. POST form data), it added backslashes before single quotes. It was meant to protect data automatically in case it was inserted into a SQL request... It granted no security gain in this context, and was a mess for any other use.
Surely that depends on when the PHP in question was originally written.
Lots of new good things in php7/php8. The typecasting is way better than before, but it still allows you to be more "dynamic" if you want to.
- Web frontend: Javascript/TypeScript
- Web backend: Javascript/TypeScript, Python
- Performant backend (where you manage threads and queues): Go, Java, Rust
- Machine learning: Python
- Command line scripting: Python
- Command line tools (binaries, eg 'ripgrep'): Rust, Go
- Mobile: Kotlin, Swift
- Systems/bare metal: Rust (discourage C/C++)
- Desktop games: C#, C++, GLSL, Rust (in ten years)
Mix and match.
The safest three to learn that give you the most flexibility are probably Javascript/TypeScript, Python, and Rust. You can build almost anything with those three.
I've done shell scripts in PHP. Mobile development in Ruby, JS and haxe. Web development with Go. Nothing is stopping you, and if you know the language it is usually not to weird either.
Recent example, while Android has adopted Rust for replacing their bluetooth stack, the newly introduced Android Games Development SDK focus on C and C++.
Or Microsoft, despite all their security speech, Azure Sphere OS and RTOS only support C on the official SDK, and the new WinUI components are all based on C++.
And naturally anyone wanting to contribute to the Rust compilers, most likely will need to brush up their C++ skills if they intend to mess with GCC or LLVM internals.
C++, though, agreed.
Sure, Rust is _fun_ but there's little demand for it right now in the market.
You didn’t use “I” at all, but it seems likely there are some other rules going on here.
"I have used PHP for years." The first sentence establishes the subject is "I".
"Like it." etc Because this sentence doesn't have an explicit subject, it is implicitly the same one, "I".
As I recall, "wa" and "ga" were the Japanese particles which established new subjects. Say you wanted to talk about Bob's new car, you'd say something akin to "About Bob's new car, is expensive. Arrived last week. Has poor gas economy."
You notice the pattern. Mimic it. Struglle with it. Persevere.Endure. Will you reach perfection? Maybe not. No problem. Satisfaction is few layers below.
Not sure that I have any tips for you. Other than that it is often helpful to remove unnecessary words when communicating. This is something I have become sensitive to over the years. I used to write a lot more voluminously but I find it is harder to convey messages to people when they are confronted with a wall of text.
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)
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.
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.
Modern PHP wears a business suit and wants to buddy the "big boys" (Java/C#) of the world. You'll have deployment pipelines, strong push towards classic OOP, strict type checking etc.
I personally think ruby for instance is leaner in its dev process in most real world projects.
Furthermore if I'm working with JS/TS, hot reloading even makes it so I don't even need to refresh the page. I can even inject code into arbitrary places with the debugger (as if I'm editing the source)!
So, all these other ecosystems are on par with the PHP...
I'm glad PHP adopting ideas from other communities, and that the community is becoming more cohesive, though.
Aside: I used to write PHP before (back in the 3 to 5 days), and worked for a big web hosting provider that had a big shared hosting customer base; PHP was by far the most popular technology in that space.So, I'm not trying to bash on PHP.
Locally however it is save, alt-tab, ctrl-r and immediately you see the result. Absolutely no waiting.
These days I rather use Quarkus for this but until Quarkus arrived this was a huge advantage that PHP had over every other language and framework I was aware of.
Also the documentation was fantastic compared to most of the stuff I have had to suffer through on Java, .Net and even React and Angular.
Every thing you may reasonably wonder about was described in a clear, straight forward way and included examples.
PHP already has caught up to others with 5.6, these days PHP 8 doesn't lack anything found in other major languages.
What is still confusing is the standard library, but only for people who never worked with C/C++ before - as most of the native PHP standard library actually originates as a verbatim copy of the C/C++ libraries.
1. WordPress uses it
2. PHP is far less terrible than I remember (having used it in very early days)
I manage a WP (woocommerce) site for a small business. It's not my day job, it needs to be simple. Most of the "day job" is handled by content management users. I have written a fair amount of plugins though to enable custom functionality and the process is perfectly fine.
I looked at Ruby, I looked at Python, I looked at node. There's nothing as simple and, frankly, as mature aside from commercial platforms like Shopify that charge an arm and leg.
The two things I can think of quickly, that I like about php, over another, is the ease of code->browser. You have to manage 0 build configurations or pipelines to get what you want working. Just download the files and open a browser. The second, is 100% transparency with third party libraries. Because of the lack of ability to compile, when I download a third party library, I'm getting their actual true source, and can much easier, navigate and understand the library right through the ide, without having to read a bunch of docs online and that it's true to source. Being able to control click into third party libraries is quite liberating.
But maybe this is just me.
There's not a lot that is comparable to the PHP ecosystem when it comes to bespoke web-based e-commerce, or anything to do with bespoke customer or content management.
If you're trying to integrate with some weird 3rd party API, chances are there's going to be something written in PHP, or you can easily pay someone to do it for you.
Not only this, but there are agencies providing long-term support for parts of this ecosystem.
Other languages with strong ecosystems in this area would be Java, or Ruby, I think. I like Java for the same reason, and would probably like Rails. Anything that has "batteries included" is good to me.
2. The PHP ecosystem is quite mature, and packages are of good quality in general
3. Dependency management works well. You will rarely end up in a state where your dependencies are incompatible between each other (something that happen often with npm for instance)
4. It's faster than python/perl/ruby
Coming from a C background, I found PHP easy to step into as many of of the underlying libraries and common functions are wrapped and available in PHP (with similar names).
In general I would never bring them up on this site. It's just not worth my time or effort. I've even gone so far as to ask people who have posted my blog posts here to take them down. Hacker News has one of the worst groupthink cases in tech, where if you speak against various core beliefs you get absolutely hammered with trolls both on the site and off of it. Having a reasonable discussion about the pros and cons of PHP is just not something this site is capable of supporting.
Also, same as many other open source languages, there seems to be a tendency to pick up every language extension someone proposes hoping that it might win over some developers, but I'm not really convinced. Does PHP really need a "match" control structure (https://www.php.net/manual/en/control-structures.match.php) when it already has good ol' "switch" and "if/else"? Of course, I also like the more flexible (Pascal/)Go-style switch statement better than the "classic" C-style one, but maybe they should have given it some more thought years ago instead of slavishly following C/C++ then and inconveniencing thousands of developers by introducing a new keyword now?
Particularly, PHP 8.1 has some changes that low key force people to update, such as the use of return types when extending a built-in classes (https://php.watch/versions/8.1/internal-method-return-types).
As someone who still owns their rent coding PHP, I really enjoy the development of the language from php 7 onwards. It certainly feels better in any way compared to the 5.x or even 4.x days.
As long as we do not get another python 2 vs 3 disaster, I am happy.
Using ASP and want to calculate an MD5? Oh, you need to pay an add-on for that. Want to send an email? Ditto.
Then there was PHP, with all included (and cheaper hosting, because Linux). I started working on a web shop and after a month ASP was legacy and PHP the new cool thing, together with MySQL instead of using... Access as "database" in ASP.
If having the same code working for a long time is the most important for you then you should probably use java or .net. Maybe c++ also but that is not as popular for building web apps.
Then I didn't have enough time to maintain it, and I stopped paying attention to it for a while.
Later I checked my homepage again, the webhosting company updated the PHP version, nothing works anymore. It is not simple to fix, so I gave up.
I am not going to spend the same amount of effort on making my homepage in PHP again. Trust is easier lost than gained.
I would still be willing to code something in PHP for someone else, because hey, if it stops working in a year or two, it's their problem, not mine. But I would warn them that something like this is possible, and in my opinion likely to happen.
It's very hard for me to treat a language seriously when I could write code that simply won't be valid PHP in 2 years time, or worse, behaving differently.
Given the severity of some past PHP vulnerabilities, being on an old version can certainly be a problem.
> I guess they might do it again from 7.x to 8.x, we'll see.
PHP 8 has some _massive_ breaking changes
So yes, let me express my antipathy toward the PHP language and its ecosystem.
I work not "well". It has hundred of issues that are not, and will never be addressed. Like the inconsistent choice of function names, the antic (if not prehistoric) way of extension managing, the clumsiness of xdebugger, the bugs in the PDO library, etc.
I spend 80% of the time trying to figure out "a hack", and spend too much time on php.net & stackoverflow hunting for the right answer.
PHP shines when you're trying to get a server-rendered web app off the ground. It's the VB6 of the web. Nothing else matches its development velocity, from keyboard to working code.
But that's just not true.
All the things you mentioned are a yum/apt/nix/pacman/ install away on Linux, and probably as simple to install on macOS. I'm sure Windows has installers for these, too.
So, it's no harder to develop in them than it is in PHP.
You could argue it's cheaper because you don't have to pay for a shared hosting provider to host your files. However that's a bit moot since even back in the day there were LAMP stack Vagrantfiles that would automate this local setup.
Also, when speaking about dev velocity or time-to-start: you forgot JavaScript, which probably has much greater development velocity than anything else.
Furthermore, PHP is rarely just PHP in production. PHP also comes with various runtime modes (CGI, FPM, etc), .htaccess rules (or nginx equivalents), a bunch of runtime language and feature toggles that are partially controlled by the system (ie your hosting provider), and some can be controlled by the application.
The ephemeral process nature of the language makes some tasks very difficult to do in a performant way (but there's caching, so that's at least mitigated).
I've seen so many developers (worked for a hosting company) come complain to us about slow servers when in fact they'd just be doing silly stuff. And it was hard to blame them, because the language encourages that model, and the "performant" was was usually orders of magnitude more difficult to implement (ie indexing, image resizing, or most types of batch processing).
I'll not go into the horrors of how easy it is to mishandle file uploads in PHP (there's plenty of those around) and how many times people got easily hacked this way.
However, I think this recurring misconceptions how easy PHP is to develop in needs to stop. PHP comes with a lot of complexities. Worst kind of complexity to learn: hidden complexity.
I'd rather say that this is actually one of the biggest selling points for PHP. Opcache and JIT works great, and reduces the overhead, but ironically, PHP is great for serverless applications.
I do a lot of work with PHP, both legacy and new code. The number one mistake I see with PHP sites set up by amateurs or cheap hosting services is running Apache+PHP on the same server as MySQL or Postgres. Separate those and performance and stability problems go away. That’s because relational databases consume as much memory as they can get, not because PHP is inherently slow or unstable.
And may His Noodly Appendages help you if you come across a function being used which has no documentation and a single decade-old comment from someone asking how it works...
And so, to plaster over it's many flaws, people start layering framework upon framework upon framework, each of which slows down the language significantly from all those shiny PHP performance benchmarks you see. And then they wonder why their shiny "what's an array? we need to transit 20 different chained method calls for that" is so slow...
And half of them are documented even more poorly than PHP itself. At least their code is in the same language you're already writing, though.
The non-documented functions are often rare and very minor and obivous functions.
This layering framework on top of frameworks sounds made up. Mostly people either use Symfony or Laravel. There aren't layers of frameworks. Your example is nonsensical. Frameworks are slower than simple code, this is true for every language.
And Symfony and Laravel are both well documented.
This comment overall seems to be written by someone who has come in with very little knowledge on PHP worked on a project for 3-4 months. When you work those style projects you're often working on poorly constructed projects. I'm pretty sure I can jump in on a project written in any language that has been poorly constructed and I will end up going wtf.
The non-documented functions are indeed often rare. That's all that can be said about them. They're about as obvious, on average, as the rest of PHP's functions are obvious.
Sure, until you want to have a UI framework, and an API framework, and ...
LOL @ Laravel being well documented. There's a tutorial and there's autogen API docs. And that's it.
This comment overall seems to be written by someone who has worked with PHP for a few years and thinks he knows everything there is to know about it.
I've been using PHP since PHP3 and professionally since PHP4, but thanks.
Nice work PHP
I haven’t worked in PHP for I don’t know how many years, and I probably still have an unfair negative reaction to it. It has a strange cultural idiosyncrasy I find more limiting than anything about the language itself. But I’m happy to see it evolve and I’m happy to see it evolve alongside other technologies I work with more readily.
> You might have heard people say that PHP was "doing serverless before serverless was a thing", and this is kind of true.
I believe that PHP is...not bad I guess? I'm sure it can make good things. But after reading this I have no idea why I would pick up PHP over any of the other capable tools out there.
I worked with PHP 9-10 years ago. Still not impressed to this day. Why should I use it? Terrible type coercion that can and will catch you with your pants down is my chief complaint -- that alone is enough for me to never touch it again. I want predictable tools, not something I actively have to fight against so I can get my job done. How is this even considered productive?
So tell me again, why should I use PHP? How will it truly help me? What does it do better than everyone else?
*Python* A disgusting level of flexibility (probably too much). You never really get trapped into anything, you can even (but should not) overwrite functions during runtime. You can make and break all the rules. Supports a number of modalities (often badly). Really killer console-based debugging tools (I love pudb for instance).
*Elixir* Insanely durable data/process model that makes it incredibly difficult to damage a working path through a non-working one. Never have your entire web app crash again. Pattern-matching and message-passing based language makes expansion easy and low risk. Macros are best used carefully but when appropriate are a breath of fresh air.
All the languages are turning complete. By definition you can solve any problem with any of them.
In the Python ML world only the matrix libraries - numpy and similar APIs like torch.tensor and jax feel natural and click in my brain. The rest - data frame, visualization, scientific libraries; I'm not very sure how to explain it, but it always feels like some context switch is needed between using Python the language, and calling out to these libraries.
I also like other languages, some because they are a pleasure to use, or give me an opportunity to learn something new... but mostly because they pay the bills.
I don't think there is anything wrong with that, these are just the tools of the software engineer, nothing more. We use the tools that are appropriate for the job, no reason to make it into something deeper than that.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
it's faster than python, but my grandma is too and she died in 1993. However, function calls are extremely slow. If you would bench something like a naieve fibonacci implementation (or ackermann's function) you would be surprised.
<?php
function fib($n)
{
if($n === 0) { return 1;}
if($n === 1) { return 1;}
$r = fib($n-1) + fib($n-2);
return $r;
}
$n= (int) $argv[1];
$r = fib($n);
printf("%d %d\n",$n,$r);
just did some measurements on my laptop: | Language | n | time(s) |
|----------------------+----+---------|
| php (7.4.25) | 42 | 422.0 |
| python3 | 42 | 90.0 |
| haskell (ghc -O3) | 42 | 13.8 |
| f# | 42 | 5.6 |
| ts | 42 | 2.8 |
| ocaml (ocamlopt -O3) | 42 | 0.98 |
| C (gcc -O3) | 42 | 0.66 |
(edit: added php version in table. ) time php fib.php 42
23s
time python3 fib.py 42
1m1s
I suspect that you're doing something very wrong, like running PHP with an active debugger or similar.If we're talking in comparison to slow interpreted languages like Python, then function calls in PHP are not particularly expensive. Debuggers can make them quite expensive though.
Edit: Just to note, PHP's execution time drops to 4s with enabled JIT.
Yes this is a microbenchmark. Yes, I know binet's formula... Yes it's weird function calls are so slow in php.
with php 8.0 (jit enabled) you get something like 120s (for n= 42)
https://twitter.com/ArkadiuszKondas/status/11196548025800212...
PHP 8.0.12:
$ time php fib.php 42
42 433494437
real 0m29.274s
user 0m29.003s
sys 0m0.105s
$ time php -dopcache.enable_cli=1 fib.php 42
42 433494437
real 0m26.341s
user 0m26.179s
sys 0m0.058s
----------------------------------------
PHP 7.3.5:
$ time php fib.php 42
42 433494437
real 10m23.573s
user 10m16.592s
sys 0m1.828s
----------------------------------------
Settings for PHP 8:
PHP Version => 8.0.12
auto_globals_jit => On => On
pcre.jit => 1 => 1
opcache.jit => tracing => tracing
opcache.jit_bisect_limit => 0 => 0
opcache.jit_blacklist_root_trace => 16 => 16
opcache.jit_blacklist_side_trace => 8 => 8
opcache.jit_buffer_size => 0 => 0
opcache.jit_debug => 0 => 0
opcache.jit_hot_func => 127 => 127
opcache.jit_hot_loop => 64 => 64
opcache.jit_hot_return => 8 => 8
opcache.jit_hot_side_exit => 8 => 8
opcache.jit_max_exit_counters => 8192 => 8192
opcache.jit_max_loop_unrolls => 8 => 8
opcache.jit_max_polymorphic_calls => 2 => 2
opcache.jit_max_recursive_calls => 2 => 2
opcache.jit_max_recursive_returns => 2 => 2
opcache.jit_max_root_traces => 1024 => 1024
opcache.jit_max_side_traces => 128 => 128
opcache.jit_prof_threshold => 0.005 => 0.005Let me give you an example;
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-python3-2.html
and https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-perl-4.html
The Python code uses ctypes, thus the unfair marginal difference.I have seen the same unjust comparison with the majority of the examples and decided to stop relying on this page for validating programming language performance.
No they do not.
Let me give you an example:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
*** You ignored the Python code that does not use ctypes.
> I have seen the same unjust comparison with the majority of the examples…
No you have not.
There are 10 different tasks.
pidigits accepts the use of third-party libraries (GMP)
regex-redux accepts the use of third-party libraries (PCRE)
That's 2 out of 10.
If someone is new to software development and in an area of the world where it's not mostly PHP shops, so bigger cities, I don't really understand the benefit.
PHP is often used to do certain things or it may be faster for you to whip something up in Laravel but if you had someone who was a complete blank slate and could chose any language and any framework in a town that doesn't have PHP jobs...why? What's the reason then?
I really think these articles come off really strange like they're trying to convince me as a "fact" but are really just nostalgia, like someone who goes off about how "cars were built so much better back in the day, there's still uses for older cars!" Maybe there is a grain of truth there and some real reasons behind it (repairability) but for 95% of use cases it's just that there's no contest, for a new driver, in an average situation there's no benefit towards going to an older car, and the guy going on about "older cars are the best", while they may have some weird reason that does actually apply to them (and as far as this analogy goes, I think Fortran is a better example than PHP in this case than PHP as for some maths applications it apparently still has an edge but that could have changed) honestly it's just nostalgia/trying to indoctrinate people...
In comparison, other programming languages are hard to figure out. Python, Ruby, Java etc all need some kind of a package manager to install dependencies (PHP apps are self-contained) and need to have the correct runtime version installed (PHP just needs to be in the general neighborhood of what's required, since most broadly used packages seem to be written in a backwards compatible fashion). This is scary and unfamiliar, and highly technical. If you're deploying on a VPS (because rarely anyone has managed Python/Ruby/Java hosting services), you've now also become the sysadmin with full responsibility for the box, including patching and downtime. Compared with shared PHP hosting, it's bonkers.
> package manager to install dependencies (PHP apps are self-contained)
PHP has Composer, which is one of the best things to happen to the ecosystem. Chances are, the piece of software you install will manage its dependencies in this way, and I'd be reluctant to install it if it didn't, as you wouldn't be able to update the software easily.
Not a fan, but that is definitely a very good argument.
Then you have the myriad of static site hosts that also take 2 clicks to host something without even having to write any code.
If we're talking about simple templates to open a store or a simple landing page there are so many no-code options like Wix/Shopify/SquareSpace/Square that I don't think PHP offers any significant advantage.
Languages tend to go through a few years of flavour-of-the-week fads (think of the Vue/React/Angular competition, and all the also-rans that we can't remember now). If you get in too early, there's a fair chance you'll bet on the wrong ecosystem, and end up with unsupported dependencies or difficult to maintain code. In the worst case, you scrap the whole thing in six months and write it for a new framework to keep it alive.
PHP went through that phase back when "we've got to support IE6 users" was a legitimate talking point. You can be reasonably confident Wordpress or Laravel are here to stay.
PHP is also fundamentally a hugely battle-tested platform. It's been ran on 486s in the broom closet, and entire rack clusters in data centres. If you have some performance or usability problem, there's a good chance someone else has had it already and worked out a solution. With some new language, your odds of "never seen that before" errors are much higher.
I look at it this way sometimes: there are the interpreted languages, the VM-based languages and then systems languages.
PHP is a good option in the "interpreted" languages category, if your problem domain is web-based, as it includes a lot of built in functionality for web-based problems. It's also open-source, reasonably performant, has an improved type system, has a C-like syntax and enjoys features inherent to a scripting language e.g. fast startup time, so would be a good option for lambdas.
Finally, one of the features that has been unreasonably good about PHP is the shared-nothing request model, which makes running a website on PHP a stable experience, in an imperfect world of weird state issues and libraries that might sometimes have a bug that leaks memory.
There are also other options in the "interpreted" category which I would fully expect people to also look into, however that's not to say PHP isn't a good contender for this space, given learning time is a limited resource.
However I would expect people to know a VM-based language and a systems-based language (or at least a bit of one) in addition.
Do you plan on creating a start-up that you intend to scale to a babillion customers? That you intend to hire teams of developers for? Probably not a good idea.
Are you a new programmer trying to figure out which language to learn first? Absolutely not. Python, Java, JavaScript, C# are much more flexible if nothing else. Anybody who tries to convince new programmers to learn PHP is doing them a great disservice.
Not interested in PHP in the slightest, but how is this myth still going around?
Wikipedia, Pornhub, Facebook (initially at least) were all built on PHP. There are hundreds of other examples.
Laravel nowadays has an outstanding reputation and I doubt it's performance is lagging so far behind Django for example.
More generally, after all these years I still need to see a story of a startup that failed because they chose the wrong stack. There are some blog posts with spurious claims in this sense, but really, when has a startup with good product-market fit and a finely designed product ever failed because they chose PHP instead of something else?
It depends what location you're in. In Europe there are pockets where PHP is very popular, where learning it can open up the job market.
In Europe there is a lot of PHP. Even in the bigger cities. And as someone who knows a lot of different programming languages, modern PHP with Laravel is pretty hard to compete with on a productivity basis.
You might as well try to convince me I should start my next business with cutting edge software written in Fortran or COBOL.
The point is not to prove that one language is better. For the most part, for web development, there isn't much difference in productivity for a programmer competent in the language between (JS/NodeJS, PHP, Python and Ruby) Java is a little more heavyweight for pure web development but if you have a bunch of backend services that need to be reliable you will find the type system to be of help.)
What is more important for productivity is a deep familiarity with the frameworks, and tools -- the IDEs CI systems etc. that you need to build and deploy your solution.
The other important thing is the ease with which you can hire programmers for that language in your market. Here in India finding PHP programmers is easier than say finding Kotlin programmers but harder than finding Java programmers. But that is not the case in other markets like the US. There is also the issue of perception of candidates. If like you, a large majority of candidates think the language is legacy, you'll end up having to pay more to hire them (because they will be harder to find -- most of the extra cost will be search costs not salary costs.)
To the extent that the PHP community can convince folks that it is not a legacy language (and it really isn't) that is good for not just the language but the overall tech community. And this article furthers that goal well.
You’re getting ready to launch, and you’re going to need a marketing site and a site with documentation and help articles for users. Do you write that site in Go?
Hell no. You hire someone cheaper whose skillset isn’t systems programming or ML, and they spit out a templated site in a weekend that looks sleek and makes a good impression, and when you need more content you tell them and they turn it around in an hour, and you spend your time on the Go stuff.
And that market, the market for Good Enough sites that front Really Good products and are fast to work with: that’s a great market for a lot of people who want to sling some code, get things done, clock out at 5 and spend time with their kids in a nice house in the suburbs. That’s why for people who want that kind of life, I recommend learning some PHP (or rather, learning the super-common frameworks that use PHP).
Hum... Probably. (I personally have a thing or two against Go, but yes, probably.)
Is the site some empty generic marketing that you'll put up to fill a feature list or is it meant to be useful? On the first case, sure, go offshore to somebody cheaper.
But on the second case, the time you can waste due to language, framework, software architecture and every other technical aspect is almost irrelevant near the time you will spend creating content. And you can't offshore the content if you want it to be great.
Yes! https://gohugo.io/ would be a great choice for that kind of thing.
I mean most of the marketing websites are build with such PHP tools.
Honestly if all I needed was a marketing site and a place to host my documentation, I would 'write' it in something like Squarespace.
But the trend didn't continue. People did it for a whilw, but then moved on to other models which still worked for PHP because few apps really need live data and concurrency like that.
The problem for PHP is that the reputation for being "a dying language" stuck.
I added more value to a tech agency and their clients with PHP than several of the senior Java guys did combined. And they were talented. Just set in their ways and lacked a focus of getting things done and adding value.
They'd waste time overbuilding shit that nobody used because it was interesting to them, not that it would create value for the client or end-users.
Also, I took over several large Node projects built by hipsters and they are the messiest code bases I've ever seen. And I've inherited a lot of trash PHP ones over the years.
Regarding the concurrency thing with PHP - ReactPHP is very nice, PHP 7 and on performance gains were massive, and real-time (search, chat, etc) can be better handled by Algolia/Pusher/etc anyway.
The Node hype train had a great run. And I still like Node. But PHP is the language of getting shit done.
it's quite a nice language, and for many many cases is certainly fast enough these days.
That said, php's online documentation is one of my "gold standards" for what good language documentation should provide. (At least it was the last time I had to reference it.)
Is php totally worthless in 2021. Absolutely not.
Is php the best language to spend your limited time learning in 2021? Almost definitely absolutely not as well.
Depends if you want a job or not.
At least in many European countries, there are plenty of them doing PHP.
In fact, when doing our Java and .NET consulting sales for Web projects, PHP is the adversary, not Python, Ruby, Go, Rust, or whatever is on the frontpage, like everyone likes to discuss over here.
Those "few dozen hours" reading PHP docs and tinkering could also be used to learn Python, Ruby, or Javascript, each of which are almost certainly better choices with broader applicability and more modern ergonomics.
Python gets you web backend + ML, Javascript gets you web backend + web frontend. Ruby gets you a multi-paradigm language with nice ergonomics and cats. PHP gets you job offers customizing Drupal and Wordpress websites.
If you already know a "scripting language most popularly used for websites", then you could choose to pick up Rust, Nim, Go, Swift, or Kotlin instead. It's much better to have a new kind of tool in your belt than a second hammer.
The world is full of so many choices. PHP has a lot of incredibly compelling alternatives. Unless your job demands PHP, you're probably better off looking elsewhere.
1. You're using it for actual work
2. Learning it will teach you something fundamental
I feel like the only way 2. might happen with PHP is if it's the first language you're learning.
By learning PHP, you are effectively locking yourself into the narrow niche of backend web development (ask me how I know!), whereas other languages have much broader target platform appeal.
As an example, the obvious competitor to PHP of Javascript already beats PHP by also providing backend web services, but also has support from AWS lambda, GCP Cloud functions, and even the somewhat esoteric embedded javascript for micro-controllers options.
> Do you shoot for what has had longevity, or what's rising?
Coming back to your original question - I think it's both. Depending on what you wanted to do, I'd pick Javascript (see above), then depending on what else you wanted to do, one of Golang, Python, C#, or Kotlin.
The question is who's hiring/where will you work, and what will you work on? In my area, there aren't many PHP shops. So it could be Wordpress or Facebook/Meta. PHP might be long-lived, but if you have to relocate to find a PHP job, does that help? Same with e.g. COBOL, Sharepoint, etc. And to be fair, what's rising has that problem outside tech centres.
Something popular like Python is generally a "better" investment, covers more bases.
But what is, if not Motorola 68000 Assembly? Do you shoot for what has had longevity, or what's rising?
Pointing out that there is not absolute certainty about what is the top choice for a better idea does not make php, or visual basic, or 68000 worth spending your time on in 2021.
Some popular choices in this bubble seem to be:
- clojure
- common lisp for some reason
- php is mentioned often here, also not sure why
- rust
- swift if you're into ios/apple, kotlin if you're into android
- typescript
What I do not like is the syntax. Call me picky but referencing attributes with -> instead of a dot (.) is ugly to my eyes and I prefer JS, Ruby or Python when it comes to the pure look of the code.
Generally I'm not a fan of dynamically typed languages because I just feel way more productive when I have proper code completion and type safety.
In general whatever works for you and makes you happy is good enough.
:)
[1] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
[2] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
The PHP language can be used as a templating language itself:
<?php
$user = 'root';
?>
<p>
Hello <?= $user ?>
</p> @page
@{
var user = "root";
}
<p>
Hello @user
</p>- Is the "your app gets initialized and torn down for every request" true for frameworks like Laravel and Symfony?
- Does this model uses OS threads? Does it uses green threads?
And then a few remarks about the language:
- I feel like the Go model is a way better model for server software than async. Since PHP is mostly used for server software, I feel like they shouldn't go with async. Python is currently going through the transition and it's painful and long.
- It feels a bit weird to see how full of objects PHP is. Modern languages (Go, Swift, Rust, TypeScript) tend to use less objects, and more plain imperative code or slightly functional code in my experience.
Yes, though heavy optimization in opcode caching and JIT keeps it fast and the primary process manager today (php-fpm) generally keeps a pool of PHP processes persistent. Each request is initialized from scratch but there's no disk nor interpreter hit after the first.
There are, of course, frameworks that simply handle HTTP requests directly (amphp, swoole) that operate as persistent application servers, so state is maintained.
> Does this model uses OS threads? Does it uses green threads?
No. PHP webserver backends are generally a long-lived forking model.
> I feel like the Go model is a way better model for server software than async
Swoole [1] offers a coroutine and channel model. It's incredibly fast and the techempower benchmarks [2] attest to the raw speed.
> It feels a bit weird to see how full of objects PHP is
Agreed. It's often way over the top with Java-esque OOP complexity. It does depend on the libraries in question but the popular ones are very heavy (Symfony). You can of course write very simple imperative code just fine too.
* If you have a memory leak your complete server will get killed some time later when running out of memory * If you have a bug which crashes your web server every running request is killed * You get all the hard-to-find concurrency bugs when multiple requests concurrently can access some objects.
With PHP's model of (1) initializing and destroying all the state on every request and (2) every request running in it's completely isolated virtual space you don't have any of these problems.
And if you really want to have a long-running server with shared space you can have that too, take a look at Laravel Octane.
However, error handling continues to be an issue. It isn't uncommon for PHP to fail silently. That would be one complaint I have against PHP.
Not only this, but PHP/MySQL is such a reproductible stack, if the code is properly written you can run the same app on tens of different server configurations (Windows, Ubuntu, CentOS, various versions of MySQL and PHP) without having to change anything.
There’s a reason why people are generally not doing scientific computing, machine learning, hardware integration, systems programming, etc. in PHP (yes, there are likely some obscure projects doing all of those, but in general, it’s not done because of limitations in the PHP runtime).
If you already know PHP, you can probably have a long and healthy career in that space. But if you’re new to programming, you’ll probably be better off learning Python or Rust, or maybe one of the platform-oriented languages like C#, Kotlin or Swift. JavaScript is also a very popular choice, because it’s currently the only thing you can easily use in the browser, but that might change with the rise of WASM.
For very large projects, however, I advise against it. The dynamic type system bites you a lot in my experience. I prefer static typing.
Don't get me wrong, I would not like to use older php these days. But just throwing 2 files onto an ftp was always php's biggest strength. It somewhat retains that for "installing" php, which still is often just "copy to server" which makes it really nice for users. But I feel it mostly lost that ease of use for people learning to program.
Now, it is still a solid language considering performance and such. It has proven itself to be. But without the easy way from zero to programmer, I am also not sure it is a better choice than anything else. Especially since it always had so many terrible footguns and at least in my opinion is also atrocious to look at.
This might be an unpopular opinion but I think PHP gained mindshare in the early days because Coldfusion (CFML) was neither free nor open source.
Disclaimer: I still maintain my PHP site from '08, so I'm current on trends.
It's a tool, use it or don't. Why do we have this weird slap fight every 2 months? It's so weird
From Pyjokes: Coding in PHP is like peeing in a swimming pool. Everybody has done it, but it's best not to talk about it.
Register globals was turned off in later versions of PHP 4. Magic quotes was turned off in PHP 7, released in 2015.
PHP today is no more "unsecure by default" than any other language.
roadrunner is a PHP server developed using golang, utilizing goroutines for high performance.
both used by Laravel Octane, providing very easy integration with the framework.
Other than that, php-fpm & FastCGI allows integration with many interestin webserver including Nginx, Caddy, Lighttpd, etc.
If self-hosting, Nginx and FPM is well-tested and very fast.
I started out doing PHP back in the everything-is-WordPress heyday. It was easy to SSH/FTP directly into sites and edit things live, and that was also a very normal thing to do. I got good at PHP and felt kind of defensive when people said how bad it sucked. Right tool for the job and all that. But, after some time doing it, I knew I wanted to break out of my PHP shell and learn another language. For some reason I felt like I could only pick one more language to learn, so I was hesitant to do so. I ended up going with Ruby. Only then did I understood what all the crap talk about PHP was about. It's probably both a language problem and an ecosystem problem. The ridiculous, complicated iteration over deeply-nested array-dictionary-combo data structures with various counters stuck in local variables here and there that I had previously considered normal vanished before Ruby's sleek Enumerable module. Of course you can code better PHP and avoid writing those kludges, but as a junior coder, that's the thing that stuck out to me when I switched from a PHP shop to a Ruby shop. Kludges and the worst inherited Frankenstein projects of my career. I swore I'd never work on PHP code again.
I spent several years doing Ruby, and along the way picked up several other languages and now can't fathom why I originally had such hesitation to pick one to learn. After gaining enough experience to be a senior engineer, a friend recruited me for a job doing PHP. This was at a big company with tens of thousands of enterprise customers, high-scale stuff. The money was good, and I had heard a lot about how PHP had cleaned up its act since the 4.x days. It's object oriented now and has a proper standard lib! I spent 3 years there, and I have to say the engineering talent there was good. Many ideas from other languages like Ruby's Enumerable had been replicated in our toolkit.
However, the vast majority of the code was still weird data structures that are unique to PHP development because of its lack's both real arrays and real dictionaries. PHP has indeed acquired standard lib, but many pieces of it still have a crap implementation. It's like they went out of their way to make lousy APIs for things like dates, times, and durations. In every other language I've used, you can easily compare time durations (is 1 hour longer than 1 minute?). PHP DateIntervals are not comparable. The API for creating a new DateTime object at a specific date is still to pass in a specially formatted string. Or, if you don't like that, you can create a DateTime for "now" and then mutate it to set the date. They may be adding language features to catch it up with other languages, but it seems like they're obstinately doing it in the most PHP-like way possible
Long-lived resources like database connections, Redis connections, etc. plagued us. We had a whole middleware in our stack dedicated to holding open proxy connections to things like MySQL. The thing that PHP enthusiasts say make it so attractive (edit, save, refresh) also bites you in the ass because PHP processes spin up and die with each request. There is no long-lived process holding onto those resources.
As of 7.3, It was still the same old PHP I knew back in 4.0. It's still crap and this time I swear I'll never work on PHP code again ;)
And yes, PHP is not as bad as it used to be anymore.
Apart from that, I don’t see a lot of benefits.