Live data from Hacker News

PHP 7 deployment at Dailymotion

engineering.dailymotion.com

161–166 of 166 posts

Re: PHP 7 deployment at Dailymotion

#161

Earlier quoted context omitted.

>And it's not asynchronous. There's not even a good reason to use a synchronous language for web development today. Not to mention the ease of running NodeJS code in a debugger, or running tests in a browser and debugging it there... This is still true today, and this fact alone makes it not worth trying out as a server language.

You just said you use Go for everything. Since when is Go asynchronous? Also, claiming that only the programming model and language that introduced the term "callback hell" should be used is a pretty big claim to make..

Go is asynchronous. [1] It's a huge point of the language, and why it's working its way to the top of the new TechEmpower benchmarks [2].

> "callback hell"

It can be ugly to look at, but it's fast.

And I thought we weren't using references to 10 years ago to judge a language? Promises minimize callback hell with a far better (more functional) interface, and async/await (usable today with transpilation) banish it entirely.

[1] https://gobyexample.com/goroutines

[2] Preliminary results: https://www.techempower.com/benchmarks/previews/round13/ -- Go has been seriously optimized over the past six months, so the last round of results is less impressive, but still strong: https://www.techempower.com/benchmarks/

Re: PHP 7 deployment at Dailymotion

#162

Earlier quoted context omitted.

You just said you use Go for everything. Since when is Go asynchronous? Also, claiming that only the programming model and language that introduced the term "callback hell" should be used is a pretty big claim to make..

Go is asynchronous. [1] It's a huge point of the language, and why it's working its way to the top of the new TechEmpower benchmarks [2]. > "callback hell" It can be ugly to look at, but it's fast. And I thought we weren't using references to 10 years ago to judge a language? Promises minimize callback hell with a far better (more functional) interface, and async/await (usable today with transpilation) banish it enti…

If using threads means the language is asynchronous to you, every language ever invented that has threads Is asynchronous.

JavaScripts asynchronous nature is nothing like that of go/etc with threads: JavaScript is inherently single threaded with an asynchronous event loop.

As for callbacks, who mentioned 10 years ago. promises were added to the ecma script last year.

Edit:

Your message seems to be inconsistent.

Every failure or less than great situation in your favoured languages has just been fixed in the last few years.

The things you complained about in another language were fixed/removed years ago but you say it's still just as bad.

Re: PHP 7 deployment at Dailymotion

#163

Earlier quoted context omitted.

Go is asynchronous. [1] It's a huge point of the language, and why it's working its way to the top of the new TechEmpower benchmarks [2]. > "callback hell" It can be ugly to look at, but it's fast. And I thought we weren't using references to 10 years ago to judge a language? Promises minimize callback hell with a far better (more functional) interface, and async/await (usable today with transpilation) banish it enti…

If using threads means the language is asynchronous to you, every language ever invented that has threads Is asynchronous. JavaScripts asynchronous nature is nothing like that of go/etc with threads: JavaScript is inherently single threaded with an asynchronous event loop. As for callbacks, who mentioned 10 years ago. promises were added to the ecma script last year . Edit: Your message seems to be inconsistent. Ever…

>If using threads means the language is asynchronous to you,

Goroutines are not threads. It's named after a "coroutine," which is an async function (like a generator) where you can pause execution of a task (to wait for IO, for instance) and then resume it at a later time. Coroutines give you implicit async/await style programming, without having to use extra keywords. The language Lua supports coroutines natively, for instance, including explicit yields to use them as generators, if you need. Goroutines give you coroutines with a bonus: Actual thread hopping (and multiple channels of communication possible, so you can effectively have more than one "yield" channel).

If you have 400,000 Goroutines running on 4 CPUs, your Goroutines can task switch between those 4 CPUs using 4 OS threads (or 8, or whatever number you determine is best for your app) as their IO events queue up. It is async, and each Goroutine has around 10k of RAM overhead, not counting data you're storing yourself (it varies by architecture, but that's a reasonable estimate; I've seen between 6k and 16k on different architectures).

Go is better async than JavaScript, because a Goroutine started on one thread can get processed on another, so a few thread-hogs won't block a task. A single Goroutine could cycle between all your worker threads, in fact, though I think it tends to stick with a single worker thread ("thread affinity"). It's probably the most asynchronous you can get in a language (only the Erlang VM/Elixir is in the same class of language, as far as I know).

Do you think PHP could handle 400,000 concurrent WebSocket connections on one server? Go can. How much RAM would you need to handle 400,000 CPU threads? Maybe 64Gb instead of ~8Gb in Go? Wouldn't CPU switching alone be starving most of the threads and redlining the CPU at that point? In my experience you start seeing serious slowdown around 5,000 threads. I'd guess you'd need 50x as many servers to handle that many connections on PHP. Maybe 100x. You need to support a million users? Is it better to have 3 servers or 300?

> The things you complained about in another language were fixed/removed years ago but you say it's still just as bad.

PHP is architecturally single-thread-per-request. Full stop. Even PHP 7 and HHVM. That simply doesn't scale as well as async, as I described above. The complaints I made were why I bailed on it years ago. I'm sure PHP has gotten a lot better than it was when I used it, but given that it still misses the mark architecturally, I have zero motivation to give it a second chance.

But given that NodeJS has far surpassed it in community support (as well as by many performance measures -- HHVM is quite fast at raw processing speed now, though not as high throughput because of the lack of true async), why is PHP still relevant except to continue to maintain existing code bases? (I've worked with several of those as well -- Joomla and Drupal in particular -- and neither was something I'd consider worth using, having looked at their internals and terrible performance. Joomla was a complete disaster; Drupal only slightly better.)

>Every failure or less than great situation in your favoured languages has just been fixed in the last few years.

Your point? Even if they all were only better as of yesterday, they're still better. Or are you defending your choice of a few years ago?

And actually, Promises have been available using polyfills for years. The proposal was made at least six years ago; I can't find the exact date, but I found a reference added to the CommonJS wiki in 2010 [1]. The Q library dates back to 2010 as well. [2]

I concede that there may have been a period of time where PHP was better than JavaScript, by the criteria I'm using today, because PHP did improve a lot after I first encountered it, while JavaScript only more recently developed its compelling advantages. It looks like Node was released in 2009? In 2009 I was using OpenResty (Nginx+Lua) to do my (small amount of) server work, which can still be more performant than both Node and PHP. But NodeJS has shot past in terms of community support, which is critical, TypeScript is awesome, sharing code on client and server is awesome, isomorphic rendering is awesome, and performance is good enough (compared to Lua) that NodeJS just wins for me, big time. Except when I need the extra speed, and for that I use Go.

Go is a brand new language, relatively speaking. So of course they're still making major improvements. Performance has already surpassed HHVM, even for raw compute tasks. It's a better fundamental architecture, giving it an edge, and performance will likely improve still more, though they're already hitting diminishing returns: Some of the worst case performance they see now may get 2x-4x faster, but typical app performance is probably only 10-20% short of optimal. I mean, they're already beating C++ on the server. How much better can they go?

Use whatever language you want; if your background and/or current job is PHP, so be it. It's not as bad as it was 10 years ago, for certain. Just don't expect anyone to pick it up based on its merits. There are too many other, stronger options available today.

[1] http://wiki.commonjs.org/wiki/Promises/A

[2] https://github.com/kriskowal/q/graphs/contributors

Re: PHP 7 deployment at Dailymotion

#164
post #16

Earlier quoted context omitted.

Hard to separate yourself from your decisions and your toolset sometimes! I certainly may check out some alternatives at a hobby level and pursue them further if they appeal to me. But for now the money in my rural city is in PHP and to a lesser extend, .NET. Don't think I've ever seen a job asking for Python, Node, etc. that didn't require an hour + commute.

If you jump on a new language early enough and are proficient enough to be productive in it, you have a chance to actually land some jobs with it without having to take a pay cut. Letting people know and engaging in the community is a requirement though. You'll meet other people passionate about it and ultimately network is everything ;) Then again I end up with php jobs anyway because I enjoy sharing my knowledge (c…

>surround myself with people who I can learn from.

This is my biggest struggle. I am the only dev in what is primarily a graphics place. I've come a long way on my own since I started here, but I miss having a mentor or at least someone whose code I can look at and learn from and know I'm looking at GOOD code.

Re: PHP 7 deployment at Dailymotion

#165
post #49

Earlier quoted context omitted.

I think people are also confusing an old issue from PHP 4.x where if you had $_POST['somevar'] it would actually have an alias automatically set as $somevar in the global userspace. This was turned off by default a long time ago and is the main real security issue when it comes to super globals. $_POST and $_GET are just the normal way to access POST and GET vars. There's nothing inherently insecure about it.

I don't think people are confusing those things at all. The comment you're replying to is quite literally saying that using $_POST['somevar'] is too easy.

> I don't think people are confusing those things at all. The comment you're replying to is quite literally saying that using $_POST['somevar'] is too easy.

Are you guys, then, saying that $_POST['id'], by itself, is less secure than a getPostVar('id') would be, by itself?

Re: PHP 7 deployment at Dailymotion

#166
post #38

Earlier quoted context omitted.

I don't get why people keep harping on super globals are being inherently bad. The variables are there. You can use them or ignore them. A variable definition harms you in no way other than a tiny bit of memory usage which is capped by the HTTP limit on POST and GET limits anyway. What? You think you're gonna get hacked because $_POST['ihaxyou'] is set to 'w00ts'? No one does this anymore: mysql_query("SELECT * FROM…

> Are you expecting it to be an integer? Easy > if(!ctype_digit($_POST['ID'])) { // throw exception here } ctype_digit is broken. Try passing integer values. ctype_digit(50) === true, but ctype_digit(100) === false. And "0000001" passes as true, which most people in the majority of scenarios would prefer not to pass. I can't remember what the even-worse-bug is with ctype_digit is, but even if you cast the value to st…

This is not so much a PHP thing as it is a different way of thinking about things. If you know something is supposed to be an integer, you can simply force it to an integer before you do anything with it:

  $id = intval(@$_POST['id']);
  if (!empty($id)) { ... }
Note: 0 shouldn't be a valid value for something called 'id', since it's likely a db id; if it is, use something other than an empty() check.
Post reply on HN