douduan1953 2016-08-14 00:39
浏览 126
已采纳

为什么WSGI Server需要在修改时重新加载Python文件但PHP不需要?

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?

  • 写回答

1条回答 默认 最新

  • duanci6484 2016-08-14 10:30
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型