Live data from Hacker News

PHP 7.2.0 Released

php.net

71–80 of 80 posts

Re: PHP 7.2.0 Released

#71
post #10

What is PHP like nowadays? I know it has a bad reputation and a history of kitchen sink design but have they managed to tame it into something more sensible? Do the docs help steer developers away from legacy issues and common bad patterns? Would anyone recommend it for new projects?

There is such a wide range of apps among visitors to this forum. It's hard to recommend something without more background. For me, PHP is all right.

But I don't follow the elite crowd's advice. I don't write classes. I don't use frameworks or routing functions, like get('/' function () { ... }). In fact I try to write as little PHP as possible. I think of it as a glue language between the browser and the database.

I spent a lot of time learning SQL inside and out, and I use one of the best databases in the world, Postgres. I try to do as much processing in the database as I can. So PHP's job is mainly to select, insert, update, or delete on a view, or to call a database function. The data that PHP gets from the database is often ready for display. So PHP just needs to wrap it in a template.

   $data = $db->query('select * from some_view where id = ?', [ $id ])->fetchAll();
   render('path/to/template.hbs', $data);
That's a super-simple example that won't even run, some cross between PHP and pseudocode, but it gives you a hint.

I just haven't let go of the newb's approach that URLs map to files.

  https://www.example.com/widgets/detail/1234
would map to /path/to/docroot/widgets/detail.php. With Apache, I don't even have to use mod_rewrite to get rid of the .php suffix and to allow /1234 as PATH_INFO. I just turn on MultiViews.

  Options +MultiViews

Re: PHP 7.2.0 Released

#72
post #10

What is PHP like nowadays? I know it has a bad reputation and a history of kitchen sink design but have they managed to tame it into something more sensible? Do the docs help steer developers away from legacy issues and common bad patterns? Would anyone recommend it for new projects?

> Would anyone recommend it Slack would, https://slack.engineering/taking-php-seriously-cf7a60065329

[deleted]

Re: PHP 7.2.0 Released

#73
post #2

Literally only object as new typehint, not the classname of the object? This doesn't really help much. https://wiki.php.net/rfc/object-typehint Looks like they went back into perl-mode

Class based type hinting has already been available since 2004 with 5.0 [1] This release adds support for the general standard object type. [1] http://php.net/manual/en/functions.arguments.php#functions.a...

Ok, that makes sense. Thanks

Re: PHP 7.2.0 Released

#74
post #68
post #57

Earlier quoted context omitted.

I'm surprised PHP hasn't had this for a while. Isn't PHP nearly 20 years old? Is it common for web languages to grow so old before they get crypto in the standard library?

> PHP 7.2: The First Programming Language to Add Modern Cryptography to its Standard Library https://dev.to/paragonie/php-72-the-first-programming-langua...

Ok, but that's different from including crypto at all. I'm surprised Go uses those algorithms in its standard library TLS stack, but they're not made available as part of the standard crypto packages...

Re: PHP 7.2.0 Released

#75
post #74
post #68

Earlier quoted context omitted.

> PHP 7.2: The First Programming Language to Add Modern Cryptography to its Standard Library https://dev.to/paragonie/php-72-the-first-programming-langua...

Ok, but that's different from including crypto at all. I'm surprised Go uses those algorithms in its standard library TLS stack, but they're not made available as part of the standard crypto packages...

OpenSSL and Mcrypt have been available for the longest time, I don't know if that counts if we word-lawyer "Standard Library" but it definitely felt like that way.

Re: PHP 7.2.0 Released

#76
post #58
post #45

Earlier quoted context omitted.

Best times from a few "do nothing" runs of Node: $ time node -e '' real 0m0.098s user 0m0.084s sys 0m0.010s Of course on my desktop it's a $ time node -e '' real 0m0.002s user 0m0.000s sys 0m0.000s tiny bit different. Python on my laptop is just slow enough that I really notice it: $ time python -c '' real 0m0.032s user 0m0.022s sys 0m0.009s Of course PHP is all 0.014, 0.010, 0.012, etc. Incidentally, this T43 is a b…

Python is faster on my laptop. time php -r '' real 0m0.064s user 0m0.055s sys 0m0.007s time python -c '' real 0m0.021s user 0m0.011s sys 0m0.005s These startup metrics are also super arbitrary anyway, as in web servers code loading is behind your app server anyway (uwsgi, php-fpm, whatever).

It's possible "php -nr ''" might be faster; -n stops loading php.ini, which is what points to all of the modules PHP ships with.

> These startup metrics are also super arbitrary anyway, as in web servers code loading is behind your app server anyway (uwsgi, php-fpm, whatever).

This is true; but only about 1-5% of everything _I_ do (as a hobbyist) faces a webserver, and then the things that do require a webserver are simplistic enough that I can write said webserver in bash and run it from socat.

Re: PHP 7.2.0 Released

#77
post #51
post #45

Earlier quoted context omitted.

Best times from a few "do nothing" runs of Node: $ time node -e '' real 0m0.098s user 0m0.084s sys 0m0.010s Of course on my desktop it's a $ time node -e '' real 0m0.002s user 0m0.000s sys 0m0.000s tiny bit different. Python on my laptop is just slow enough that I really notice it: $ time python -c '' real 0m0.032s user 0m0.022s sys 0m0.009s Of course PHP is all 0.014, 0.010, 0.012, etc. Incidentally, this T43 is a b…

It seems almost all the time node.js runs hello world is spent loading its own modules. You should try something like this: // watch.js var file = process.argv[2] console.log('press enter to run '+file) process.stdin.on('data', function(){ var [s1,ns1] = process.hrtime() for(var k in require.cache) { delete require.cache[k] } require(file) var [s2,ns2] = process.hrtime() var s = (s2-s1)+(ns2-ns1)*1e-9 console.log('ti…

Hmm, very interesting. Something to definitely keep in mind, thanks.

Re: PHP 7.2.0 Released

#78
post #66
post #53

Earlier quoted context omitted.

> PHP is still slightly better in terms of speed of deployment When it comes to securing the deployment I think Python/Ruby would be better though - if you factor that in I would say it would be faster for me to deploy a python app than configure php to be secure.

How do you justify that claim? I'm pretty sure it's the other way around.

You have to write proper configs for php-fpm, configure apache if you use that etc. All of this takes time, its very easy to deploy php app, but configuring server to sandbox it properly takes time and should be accounted for.

Re: PHP 7.2.0 Released

#80
post #78
post #66

Earlier quoted context omitted.

How do you justify that claim? I'm pretty sure it's the other way around.

You have to write proper configs for php-fpm, configure apache if you use that etc. All of this takes time, its very easy to deploy php app, but configuring server to sandbox it properly takes time and should be accounted for.

This response doesn't float right with me. Are PHP fpm configs horribly wrong by default? Do you not put a service like nginx/haproxy/apache/gunicorn/caddy in front of Ruby/python for a serious production deploy? Do you legitimately expect to deploy ruby/python without spending a minimum of an hour going over configs and assuming everything is right for your application by default while also assuming the opposite for PHP? I read the PHP configs for fun micro optimizations. It takes less than 10 minutes to find your framework's best practice list and apply them.
Post reply on HN