Live data from Hacker News

PHP 7 deployment at Dailymotion

engineering.dailymotion.com

61–70 of 166 posts

Re: PHP 7 deployment at Dailymotion

#61
post #39
post #21

Earlier quoted context omitted.

>As a JS/Web developer you learn to ignore the hatred of the web that it seems to get from the HN crowd. As an occasional full stack developer (not by choice), I can confidently say that the reason people hate on popular web tech is that it is uniformly terrible compared to non-web tech. I'm no fan of Java, for example, but I'll take it over PHP any day. JavaScript is so bad that I (and many other developers) will pu…

This is the typical "hatred of the web" that I usually ignore. ES2015 brought a ton of huge language improvements that are still filtering out into usage, Babel means you can use them all now without waiting for browsers to implement them, Webpack gives you a ton of flexibility for packaging it, Eslint allows you to lint in a completely pluggable way, NPM (and now Yarn, which fixes many of NPM's problems at scale) al…

JS5 was already fine too.

With ES2015 the crowd that hasn't had time to learn JS can just write it like it's Java/C#, with the class syntactic sugar of ES2015.

Re: PHP 7 deployment at Dailymotion

#62
post #14

Hack and HHVM solves what is, IMO, the worst feature of the default PHP runtime environment[0] - and that is the superglobals. It wasn't mentioned in the post from Slack, but default superglobals and the earlier register_globals design decisions are the worst and most impactful wart in PHP. Because it was designed as a templating language, the default web server interface, which is CGI - will auto-expose all variable…

Agreed, at Amazon you are allowed to use any programing language except for PHP for this very reason, it is the least secure. PHP is officially banned as a language.

Re: PHP 7 deployment at Dailymotion

#63
post #14

Hack and HHVM solves what is, IMO, the worst feature of the default PHP runtime environment[0] - and that is the superglobals. It wasn't mentioned in the post from Slack, but default superglobals and the earlier register_globals design decisions are the worst and most impactful wart in PHP. Because it was designed as a templating language, the default web server interface, which is CGI - will auto-expose all variable…

Does it also solve the variable scope issue? I moved away from PHP a while ago, but all this sounds like a step in the right direction. if (true) { $a=1; } echo($a); // outputs 1

A decent IDE such as phpstorm will flag that with a warning (assuming $a wasn't already defined before)

Re: PHP 7 deployment at Dailymotion

#64
post #38
post #14

Hack and HHVM solves what is, IMO, the worst feature of the default PHP runtime environment[0] - and that is the superglobals. It wasn't mentioned in the post from Slack, but default superglobals and the earlier register_globals design decisions are the worst and most impactful wart in PHP. Because it was designed as a templating language, the default web server interface, which is CGI - will auto-expose all variable…

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 string [ex: ctype_digit((string)$var))], there is some value that still passes for true when it shouldn't - do not use ctype_digit. is_numeric() is also unusable for validation [is_numeric("123e4") === true]. is_int() is a strict type-check so can't solely be used to validate request variables which are always strings (...or arrays, more below).

The only correct ways to verify that a variable contains either a valid numeric string or integer is by comparing type, and then using a regex or a double string-then-int cast.

ex: unsigned database ids: if ((is_int($var) || is_string($var)) && preg_match('/^[1-9]\d*\z/', $var)) { // definitely an int > 0 }

ex: signed integer: if (is_int($var) || (is_string($var) && (string)(int)$var === $var)) { // valid int (including negative values) }

Frankly, developers who don't understand how request variables are handled in PHP have zero chance of properly validating input. Find any site/app written in php, even if built on any of the major frameworks. You can instantly break 30-50% of them by passing an array where a string is expected.

Find an app that takes "?query=hello+world". Instead pass in "?query[]=hello+world". Want an example? Log in to Facebook, then visit this search page[1]. Look at the query string and then what was searched for - and the contents of the search box. Bam, even Facebook gets it wrong! Same thing with Symfony's search[2]. Or Packagist (composer's package manager repository)[3]. More seriously at Yii[4], which exposes an internal error to users as they try to string-trim an array ("Error - trim() expects parameter 1 to be string, array given").

Most developers - including many seniors who have been exclusively coding in php for years - have no clue. You will either cause a 500 Internal Server Error, or your input array will result in an output string of "Array" if they typecast your array to the string they expected. Even the major frameworks, when you pull user-submitted values, simply passthrough the value submitted. Your app expects a string (or a string that contains a numeric value), and instead any user who knows the "[]" syntax can pass in an array.

Really reflect on this fact. Most applications start handling a submitted array value as if it's a string. The bugs this produces are astronomical in some cases.

If you think your framework protects you, think again. The frameworks' request objects also do not have strict type checking. The same goes for their form and model validation classes; if you're using the built-in "integer" or "numeric" validators, you're probably doing things wrong.

It's a nightmare. You could try to blame PHP, but really it's the developers - including the developers of every major well-known framework I've ever touched - that have absolutely no clue.

Related tangent: comparing password and password confirmation fields. Many developers do if ($password == $passwordConfirm) {}. In PHP 5.x, "10" == "0xA" (so type "10" in password field and "0xA" in the confirmation field, and it passes validation). This changed in PHP 7 though. There are only two correct ways to verify that two strings are exact: $password === $passwordConfirm (triple equals), or strcmp($password, $passwordConfirm) === 0.

[1] https://www.facebook.com/search/top/?q[]=hello

[2] https://symfony.com/search?q[]=hello

[3] https://packagist.org/search/?q[]=hello

[4] http://www.yiiframework.com/search/?q[]=hello

Re: PHP 7 deployment at Dailymotion

#65
post #40
post #3

We did the same thing with HHVM, and had VERY similar results; getting it to work was plain hard, and i had a lot of concerns about our ability to ever go back. Before we ever launched with HHVM completely, PHP7 came out. With only a few weeks of work, we managed to make the switch. The gains were identical to what we saw on HHVM, only the experience of working with PHP7 was so much easier for everyone involved. Havi…

Hack's influence is all over PHP7, unsurprisingly. As someone still bound to PHP due to technical debt, I'm thrilled this happened. PHP still has warts, but changes in 7 are tantamount to ES5 :: ES6. The language feels more mature, real, sensical.

A much needed overhaul to the utility functions (array, strings etc) should be the next step.

Re: PHP 7 deployment at Dailymotion

#66

> During few months, this project wasn’t the priority, so we decided to wait the release of PHP 7 to compare performances. I have no idea why the author is choosing to write in such a strange grammatical style.

Not everyone is a native English speaker. I am not and probably sound as weird. If it makes sense though who cares?

Re: PHP 7 deployment at Dailymotion

#67
post #12

I used to run one of my site (25K unique visitors a day) on PHP 5.3, when HHVM came out with stable version I shifted to HHVM and I had similar experience. Now I am running it on PHP 7 and I have to say I am more than happy with results. As much as PHP is not cool for today's developers it has served on some really high traffic sites and stayed useful even with the test of time. P.S. Now I wish somebody just implemen…

HHVM implements a good async I/O system [0] and has the ability to run HTTP.

[0] https://docs.hhvm.com/hack/async/introduction

Re: PHP 7 deployment at Dailymotion

#68
post #43
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…

In all seriousness, shouldn't all the frameworks just have some validation built in? Being that this is such a "global" WTF problem. I would love to be able to say ini_set('sanitize_rest', true) and deal with errors that might result from that knowing at least the strings are safe. Or have functions like sanitize_string($str) and have the documentation encourage it everywhere. I mean, aren't we all just implementing…

[deleted]

Re: PHP 7 deployment at Dailymotion

#69
post #39
post #21

Earlier quoted context omitted.

>As a JS/Web developer you learn to ignore the hatred of the web that it seems to get from the HN crowd. As an occasional full stack developer (not by choice), I can confidently say that the reason people hate on popular web tech is that it is uniformly terrible compared to non-web tech. I'm no fan of Java, for example, but I'll take it over PHP any day. JavaScript is so bad that I (and many other developers) will pu…

This is the typical "hatred of the web" that I usually ignore. ES2015 brought a ton of huge language improvements that are still filtering out into usage, Babel means you can use them all now without waiting for browsers to implement them, Webpack gives you a ton of flexibility for packaging it, Eslint allows you to lint in a completely pluggable way, NPM (and now Yarn, which fixes many of NPM's problems at scale) al…

"My language that I use all the time (definitely no Blub paradox here) isn't bad, look at all these random features it has!" Sorry, but that isn't a reasonable argument. Having used all the stuff you mentioned, and many other languages, JS is relatively not good.

> Typescript

Is essentially an entirely different language. But I agree, it's a vast improvement.

> It's very possible to write--and deploy--very high quality Javascript today.

But the language doesn't actively assist in precluding low-quality code, and most production JS that wasn't transpiled is low-quality.

Re: PHP 7 deployment at Dailymotion

#70
post #31

Earlier quoted context omitted.

See I can't decide on this. What is a good language? Java? If all newbs picked up Java as language #1.. would their apps be better? Or would the really bad devs writing copy paste stack overflow code just be unable to understand it, so they would quit? Like is it safer because it keeps out knuckle-draggers, or safer because it is actually safer? Cuz I can write some horrible Java code that will rival anything you can…

As I said, by all means you can write bad code in good languages. I'm not saying choosing a good language excludes all possible bad code, only that they provide some guidance on better practices. So you mention Java. Java enforces OOP. Now OOP may not be the best paradigm always, however its a vast improvement on inline procedural PHP. That isn't to say you can't write some horribly modelled Java code, but the fact t…

the only difference would be the bad programmers would write a get _global_input_variable_enterprise_factory instead of using $_GET.

this argument is pointless.

Post reply on HN