chyoo CHENG
chyoo CHENG

Reputation: 720

Why WSGI Server need reload Python file when modified but PHP not need?

I'm confused about this question. When do Django development, if I have modified the py file or static file, the build-in server will reload. But on PHP app development, if I have modified the files, the Apache Server do not need reload and the modified content will show on browser.

Why?

Upvotes: 2

Views: 399

Answers (1)

knbk
knbk

Reputation: 53669

Django used to do the same back when CGI was the most common way to run dynamic web applications. It would create a new python process on each request, which would load all the files on the fly. But while PHP is optimized for this use-case with a fast startup time, Python, as a general purpose language, isn't, and there were some pretty heavy performance drawbacks. WSGI (and FastCGI before it) solves this performance issue by running the Python code in a persistent background process.

So while WSGI gives a lot of benefits, one of the "drawbacks" is that it only loads code when the process is (re)started, so you have to restart the process for any changes to take effect. In development this is easily solved by using an autoreloader, such as the one in Django's manage.py runserver command.

In production, there are quite a few reasons why you would want to delay the restart until the environment is ready. For example, if you pull in code changes that include a migration to add a database field, the new version of your code wouldn't be able to run before you've ran the migration. In such a case, you don't want the new code to run until you've actually ran all the necessary migrations.

Upvotes: 1

Related Questions