News for hackers. Stuff that matters.
Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by fulafel on Sunday March 17, 2024 @06:10AM (#39733250)
If PHP doesn't recompile your script imports, how does the reload tracking work with dependencies? Or does it punt somehow (eg only reloads your script but not is imports)?

There are various implementations of this kind of autoreload system for Python but it always seems to come with compromises on semantics (different initialization order causes behaviour differences).

Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by JonathanBeuys on Sunday March 17, 2024 @06:35AM (#39733381)
Imports are also updated the moment you update the imported file.

I'm not sure if PHP stores any compiled binary or byte-code at all. Maybe it compiles it all on each request. It's super fast though, even with tons of imports.

My guess would be that it keeps compiled versions of each file in memory and on each request, it walks down the whole import path. And when it encounters a changed import, it compiles only that one.

Would be cool if someone with more knowledge could shed a light on what is actually happening.

Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by dsego on Sunday March 17, 2024 @06:39AM (#39733398)
Afaik, PHP can have opcode caching enabled or disabled.
Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by JonathanBeuys on Sunday March 17, 2024 @06:44AM (#39733423)
True. I see a "Zend OPcache" section in my phpinfo().

It says:

    Cache hits   4746528
    Cache misses   38875
Both values go up every time I execute phpinfo().

I wonder why. Shouldn't "Cache misses" only go up when a source file is changed?

Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by raziel2p on Sunday March 17, 2024 @09:08AM (#39734246)
AFAIK, before PHP even accesses opcache for bytecode, it checks the file's metadata (last modified, most likely). So an updated file might never trigger a cache hit or miss.
Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by JonathanBeuys on Sunday March 17, 2024 @10:08AM (#39734588)
If it does not access the opcache, against what is it checking the last modified date?
Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by alecsm on Sunday March 17, 2024 @07:50AM (#39733788)
If you're talking about importing third party dependencies, composer takes care of that.
Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by raziel2p on Sunday March 17, 2024 @09:10AM (#39734259)
In PHP, dependencies are just .php files just like your own code, it all works the same.

PHP code is also typically far less complex than Python modules - modern PHP code consists of a single index.php with procedural code, and everything else is just class / function definitions, so there are no side effects.

Re:Django REST framework: 3.15.0 Release (Django 5.0 support) by smashed on Sunday March 17, 2024 @02:01PM (#39736485)
Most major PHP frameworks like laravel, symfony, Drupal, Magento develops all kinds of complex caching layers to work around PHP's stateless 1 request/1 execution model, essentially poorly recreating shared application state you would get for free with a long running worker process.

Python's import model is not without its flaws either, but at least you have a working application state, no need to fully initialize your app for every single request.

For simple apps that are contained within a few files, PHP is hard to beat for simplicity and speed.