News for hackers. Stuff that matters.
Re:Taking PHP Seriously by mikey_p on Thursday October 13, 2016 @05:44PM (#12704314)
The downside is literally exactly the same as the upside: you have to bootstrap from literally nothing for every single request. Think about how ActiveRecord in Rails reads from the DB schema to generate it's magic methods, etc. This is usually done on startup or at least cached in memory once it's loaded. This is something that you have to manage more carefully with a PHP app since you can't have anything initialized before a request starts. Code paths, auto-loaders, database connections, config files, etc. All that has to happen over and over for each request. You can cache that stuff, but it's still overhead that isn't central to handling a request.

There's actually work being done to build PHP frameworks that get around this with ReactPHP, ZeroMQ, Photon, etc. Essentially this is what HHVM does as well, by at least keeping your compiled bytecodes in memory (similar to APC/eAccelarator/ZendOptimizer, etc).

See: http://reactphp.org http://www.photon-project.com https://gnugat.github.io/2016/04/13/super-speed-sf-react-php...

Even the idea of an alternative runtime for PHP (ala HHVM) is nothing new: http://quercus.caucho.com

Re:Taking PHP Seriously by bkanber on Thursday October 13, 2016 @07:11PM (#12704951)
> Code paths, auto-loaders, database connections, config files, etc. All that has to happen over and over for each request.

So? If it takes < 1ms, what's the harm? And opcode cache comes out of the box and most PHP DB drivers can use connection pooling.

We serve most of our requests in < 10ms, and we're not even on PHP7 yet.

Re:Taking PHP Seriously by pharrington on Thursday October 13, 2016 @09:27PM (#12705581)
Is machine computation mostly responsible for your revenue? If so, would it make more sense to measure web server responses in terms of cpu cycles and such instead of time?
Re:Taking PHP Seriously by colllectorof on Thursday October 13, 2016 @07:42PM (#12705122)
>Think about how ActiveRecord in Rails reads from the DB schema to generate it's magic methods, etc.

All the magic you ever need can be dynamically created in __get, __set and __call. It works, it works well, and it makes not only reasoning, but also deployment an order of magnitude simpler.

>Code paths, auto-loaders, database connections, config files, etc.

Use a single code path, a single autoloader and a single database connection. Cache the opcodes of stuff you load. Write config files and templates in pure PHP, so they're cached as well. Done.

I've never, ever had problems with bringing PHP page generation time below .1 seconds. Usually it took something like .03 seconds on crappy hardware. And that was without extensive caching of DB results or anything else that's particularly clever.

Re:Taking PHP Seriously by SolarUpNote on Thursday October 13, 2016 @06:56PM (#12704841)
Doesn't Opcache take care of that? Using a large framework isn't really a problem because all of the classes, configuration, etc is all kept in ram.
Re:Taking PHP Seriously by TazeTSchnitzel on Thursday October 13, 2016 @07:18PM (#12705000)
The code itself is held in shared memory, so it doesn't need to be recompiled. However, you still have the application startup time to worry about.
Re:Taking PHP Seriously by toast0 on Thursday October 13, 2016 @06:28PM (#12704656)
> Code paths, auto-loaders, database connections, config files, etc. All that has to happen over and over for each request.

Do you most of those need to happen at all, ever? In my mind, auto-loader is a sign that nobody knows what's being loaded (if they did, they would just require it). Requires should be full pathed (because have you seen what happens when you search the include path). Mysql_pconnect has been doing connection pooling for a long time, mysqli supports it too (so yes, you do need to connect sometimes), anyway, if you're loading a framwork, loading that probably takes longer than connecting to a mysql server in the same colo.

Re:Taking PHP Seriously by dpcx on Thursday October 13, 2016 @07:50PM (#12705162)
IMHO, developer time is more expensive than CPU time; I don't want or need to have to write out all of those requires. That's the job of the autoloader. And if I'm writing my code remotely well enough, each section only uses the things that it needs. Granted, there may be some things that each request get that they don't need with the autoloader. But I can optimize later. "Make it work, make it right, make it fast"
Re:Taking PHP Seriously by Twirrim on Friday October 14, 2016 @12:41PM (#12709262)
> IMHO, developer time is more expensive than CPU time; I don't want or need to have to write out all of those requires.

Every wasted millisecond on the server side matters. It impacts scalability, customer experience (and revenue) etc. You should take every easy win you can get there.

Not doing full includes is just ridiculously lazy. It doesn't take that long to write them out, and your IDE can help you out there. I bet you spend more time on social media during office hours than you'd ever save from not having to type out those import statements.

Re:Taking PHP Seriously by bpicolo on Saturday October 15, 2016 @01:40PM (#12714896)
Except you still need autoloading configured for most libraries in the ecosystem to work, unless you want to manually chain absolutely huge quantities of requires.
Re:Taking PHP Seriously by avisser on Friday October 14, 2016 @10:20AM (#12708227)
> I don't want or need to have to write out all of those requires. That's the job of the autoloader.

Or the IDE. IntelliJ or ReSharper does that for me. And I like dealing with any naming conflicts right then and there, which those tools allow me to do.

Re:Taking PHP Seriously by cagataygurturk on Saturday October 15, 2016 @08:24AM (#12713725)
> IMHO, developer time is more expensive than CPU time

I see that you've never worked on a project where the CPU time needed to handle the traffic with crappy code is much more expensive than developer time to write efficient software.

Re:Taking PHP Seriously by dpcx on Tuesday October 18, 2016 @11:14AM (#12735242)
I have. And one of my first steps after starting to clean things up is to switch to composer and autoload; because then I can start ripping things out much more easily, and still make improvements to both code quality and performance.
Re:Taking PHP Seriously by toast0 on Thursday October 13, 2016 @09:19PM (#12705553)
Users' time is more important than developer time or CPU time.

Burning cpu and maybe i/o looking for code all over the place is going to make it really hard to make it fast later.

Re:Taking PHP Seriously by stephenr on Friday October 14, 2016 @09:40AM (#12707969)
> In my mind, auto-loader is a sign that nobody knows what's being loaded

Or that, you know. There is an extremely powerful language feature and the developers are taking advantage of it.

Re:Taking PHP Seriously by forgottenpass on Friday October 14, 2016 @12:42PM (#12709272)
The downside is literally exactly the same as the upside: you have to bootstrap from literally nothing for every single request.

Well, it depends on how it's implemented, and how pedantic someone gets about what "shared nothing" means.

There is a long history of unix daemons that initialize, listen(), and then fork off a child process whenever a client connects. The child does all the work and the parent goes back to listening. You can do the "up front" work once and then each child can only modify their copy of the data, preventing it from interfering with the next request.