Live data from Hacker News

Taking PHP Seriously

slack.engineering

141–150 of 673 posts

Re: Taking PHP Seriously

#141
post #16

I work on PHP at my day job (in a public company), before this, I came from Ruby, and .NET before that. I'm convinced the reason so many successful projects use PHP, is not because of any inherent nature of the language. I think it's the people who use it. They just don't care. A successful project needs to be started by someone that cares just enough, but not too much. If you're programming in PHP, you're not runnin…

In 2 words: shit happens.

Re: Taking PHP Seriously

#142

Earlier quoted context omitted.

People that have that mentality, is like: - You sit in a dining table with 50 different utensils. White wine glass, red wine glass, water cup, salad fork, dinner fork, dinner knife, teaspoon, soup spoon, bread plate with knife... - When the food is served, you take the food, drop it on the floor, eat it with your face (not even using your hands). "get shit done"... use spoon as a knife and knife as a fork, or try to…

Works for my 1 year old. Guess what: She hasn't starved.

Sure. But if she does the same at age 10, it would be time to have a conversation. Unless you are not very engaged in your parenting.

Re: Taking PHP Seriously

#143

Earlier quoted context omitted.

I'll offer an alternate hypothesis. Some companies are succeeding in spite of php. There are many, many users of php, and we'd expect that there would be considerable variance, with some users doing awful (no traction, buggy sites, etc) and some hitting home runs (facebook). Because it's such a popular language, it will have users across this entire spectrum. It's easy to cherry-pick the winners and miss all of the t…

I've gone one step further and created a template: Some companies are succeeding in spite of [insert language]. There are many, many users of [insert language], and we'd expect that there would be considerable variance, with some users doing awful (no traction, buggy sites, etc) and some hitting home runs (facebook). Because it's such a popular language, it will have users across this entire spectrum. It's easy to ch…

Your template is far less interesting than the original statement. PHP spent a pretty long time as basically the lingua franca outside the enterprise world (and even some places in it), and there are still domains where it holds that title (e.g. WordPress alone outweighs many languages' ecosystems), so the phenomenon the parent was describing applies more to PHP than to some arbitrary language you could insert into this template.

Re: Taking PHP Seriously

#144
post #16

I work on PHP at my day job (in a public company), before this, I came from Ruby, and .NET before that. I'm convinced the reason so many successful projects use PHP, is not because of any inherent nature of the language. I think it's the people who use it. They just don't care. A successful project needs to be started by someone that cares just enough, but not too much. If you're programming in PHP, you're not runnin…

This is one of the most accurate comments I've ever read on HN. Completely agree and can further back it with personal experience.

Re: Taking PHP Seriously

#145

The article points out that arguably the best part of PHP is the "shared nothing lifecycle". That each request starts new, and the process dies at the end of the request. It's by far my favorite part, and I completely agree that it makes "reasoning about" (boy do I hate that phrase...) your program much easier. Why are there no other "competitors" in this space? Why do most other languages go with the alternative rou…

The real question is why does PHP depend on globals or thread locals for request state at all? PHP's "new process per request" is a solution to a problem that PHP created for itself. In other languages, the request handler receives the request state as an argument, so when the request completes there is no state to reset.

> It seems like it would be easier for everyone involved. You wouldn't need much of a GC when the process is killed every time, you don't need to worry about async IO or multi-threading or catching errors or any of the other annoyances that come with most of the traditional "event loop" way of doing things.

Firing up a new process (or even a new thread) for each request is very expensive--much more so than a generational GC. Async IO also mitigates this (why have 10K parked threads consuming memory all your memory if all of them are stalled, waiting for database)? Services that spawn a thread for each request run into the C10K problem--they can only serve 10K simultaneous clients. Regardless of your concurrency model, you can't ignore errors--you still need to dispatch the right status codes and error information (not to mention logging, etc).

You should check out Go. You write concurrent code and the runtime effectively manages a thread pool under the covers so you get all of the performance benefits of async programming with the developer-friendliness of synchronous programming. In the case of a web app, you just need to write your request handlers--the web server manages the request concurrency for you, and the language's runtime manages the parallelism.

Re: Taking PHP Seriously

#146

That example of "Surprise type conversions" is crazy. Did not know that. While i do not think PHP is a perfect programing language. There is one think i LOVE about PHP, it is that the PHP "community's" default way of documenting code behavior is to make a small example. When i read most other languages documentation i read it. Then i need to make a small test to verify that i understood it. All those tests takes a lo…

In my experience code examples as documentation are far more common than actual documentation (e.g. guides, user manuals), but perhaps I just haven't worked in a language where the opposite is true.

You can take a look at the node api docs... there are some areas (particularly in crypto), where it's really hard to understand what you need to do, as there are pretty much no examples of actually exercising said code. So you go searching via google, find a similar example, look at the docs again, and hope that you got it right.

It's harder still when you're trying to en/decrypt data from multiple programming languages... Java is particularly painful as well, since a lot of the things that are "standard" are abstracted behind class structures with naming that differs from the standards.

Re: Taking PHP Seriously

#147

Earlier quoted context omitted.

> You wouldn't need much of a GC when the process is killed every time Yes, you do. You'd be surprised how easily memory balloons out of control unless you regularly run a GC. Log minor collections sometime in Java or JS engines if you don't believe me… Even worse, if you don't run GC regularly, you will suffer terrible locality as execution continually grows the heap (not to mention the overhead of continually reque…

Sorry, but GP is right here... you really don't need GC if the entire process ends and the memory is completely freed at the end of the request. Not that I feel cgi is the most efficient way to handle requests... but not needing the complexity of GC could be one advantage of that approach...

It may seem that way at first, but space leaks during individual requests are way too easy otherwise. Think about something as simple as, say, parsing Mustache templates. The parser is probably internally making lots of little substrings to record the names of directives as it comes to them. You would think that this is O(1) in space, since you only need one (or a small number) of strings at a time, but without a GC the space requirements balloon to O(size of input). Being able to dump the memory at the end of a request doesn't help you if you keep blowing out your cache during each one.

I speak from experience: there have been many attempts to mandatorily delay collection until the end of the event loop in browsers, to achieve greater responsiveness. It has always failed. You can add heuristics to try to preferentially collect at the end of the event loop, but you really need to be able to GC anytime.

Re: Taking PHP Seriously

#148
Sorry to sound so dramatic but I don't know how to put this in better words:

After reading this thread, is there even a proper way to measure how good a language is (trade-offs, benefits down the road)? Having done web stuff in PHP and Python I think both are terrible. So, how would a programmer trying to avoid his own biases and anecdotes find what tools are right for each job? Maybe I didn't "liked" PHP and Python because I'm a terrible programmer. Or maybe I only worked with awful teams.

Is there any science involved or should I make my decisions based in what blog post I read that week? How can I actually trust the opinion of companies/engineers if they are so invested in that tech? Who would admit that after investing millions on it they didn't actually think it was worth it? There's no way that I'll be able to have deep knowledge about all the languages that are out there.

The sad thing is that I end it up choosing whatever is popular and half sane because not finding (updated/well-maintained) libs or tools you need is worse than picking a niche language that might do the job better.

Re: Taking PHP Seriously

#149
post #4

Earlier quoted context omitted.

The language is not beautiful, it is full of signature and func naming inconsistencies [1] it inherited from C. The devs are ultra-conservative and stubborn to cause BC even at major version bumps (like the forever-incorrect ternary associativity [2][3]). But PHP7 is both fast and productive with many modern first-class features. You can in fact write excellent code without much effort that will handily outperform Py…

> The language is not beautiful, it is full of signature and func naming inconsistencies [1] it inherited from C. It was consistent with the thing it inherited most of it's syntax from so that makes it inconsistent? > The devs are ultra-conservative and stubborn to cause BC even at major version bumps (like the forever-incorrect ternary associativity [2][3]) You shouldn't be judging the way operators work in one lang…

> On the other hand, the PHP devs changing the ternary would cause major problems for anything that uses it.

If you read the thread, no one could actually recall having ever seen code that relies on the current behavior. It has been discouraged in the docs for years. The stop-gap proposal was to have PHP7 deprecate it with a warning rather than silently changing the behavior. Then change the behavior in a future version (say php 8).

Disregarding any of that, this is an admitted language bug. It was not ever meant to work this way. Do you have a list of languages where ternary works backwards? PHP devs don't just work in PHP. Having one C-style language work this way and another C-style language (js) in another editor tab work the opposite way is a major PITA.

Re: Taking PHP Seriously

#150
Really, the worst part of PHP in my experience has been the debugging facilities. Print-line debugging just doesn't cut it anymore, and things like xdebug and phpdbg just aren't elegant, are hard to configure properly, and don't work for all the relevant scenarios (trying to debug PHP running in a docker container is not a fun task).

The quality of open-source libraries in the ecosystem is also pretty below what I've come to expect from other languages, and then half of them are c-lang PHP hybrids that are more difficult to manage, update, and install.

I think the author failed to mention the downsides of no long-running processes either. Shelling out to e.g. memcached for configuration setup (especially when memcached might not live locally) isn't particularly fun. Not to mention this has made it difficult to integrate into some useful things, like GRPC[http://www.grpc.io/] which can't use PHP as a server as of yet.

Then there are all sorts of random deployment gotchas, like proper opcache configuration.

PHP is a pretty wart-filled language. It's usable, but I wouldn't make it my first choice in any situation, given a choice.

Post reply on HN