I know that PHP code is compiled to the bytecode and reexecuted on every run (i.e. on every page request). So engine should redefine all used classes, functions, variables, etc. on every request.
When using full-stack frameworks like Laravel or CakePHP this also means that on every request the same bootstrapping work is done again and again, like parsing configuration files, registering routes, autoloading classes, etc.
This seems to be very unoptimal way of handling such stuff. And even caching, be it OPcache or framework caching system, is not helpful enough, because script still needs to be executed.
On the other hand, application based on engines like NodeJS or Ruby compiled and bootstrapped only once during startup. So I imagine they should have better scalability than PHP.
But PHP is so popular and even Facebook uses it. So I wonder, what is the right choice for a website that may experience heavy load? Is using PHP with full-stack framework for such purpose a bad idea?
I know that PHP code is compiled to the bytecode and reexecuted on every run (i.e. on every page request). So engine should redefine all used classes, functions, variables, etc. on every request.
Starting in PHP 5.5, an opcode cache comes default. Prior, APC could be used. You can also use something like HHVM to further improve performance via JIT-compilation (PHP 7 will include similar improvements).
When using full-stack frameworks like Laravel or CakePHP this also means that on every request the same bootstrapping work is done again and again, like parsing configuration files, registering routes, autoloading classes, etc.
Laravel (I can't speak for CakePHP) only loads classes when they're used - most of your classes won't ever be loaded in an average request. Most paranoia about using larger frameworks like Symfony/Laravel is just that - paranoia.
This seems to be very unoptimal way of handling such stuff. And even caching, be it OPcache or framework caching system, is not helpful enough, because script still needs to be executed.
Opcode caching and framework caches (files, Redis, etc.) offer tremendous benefits that you're rather cavalierly dismissing here. Yes, code needs to be executed for every request (although something like Varnish can reduce even that) - but such a thing is true for any language and any framework.