Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100113

Re: Understanding Python from a PHP coder's perspective

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Understanding Python from a PHP coder's perspective
Date 2015-12-08 09:00 +1100
Message-ID <mailman.35.1449525620.12405.python-list@python.org> (permalink)
References <f39f97f5-d7a1-4d7c-a7ac-527c2ffff76b@googlegroups.com> <44d92f52-4f92-470d-a724-102a14d185de@googlegroups.com>

Show all headers | View raw


On Tue, Dec 8, 2015 at 8:21 AM,  <villascape@gmail.com> wrote:
> Per https://wiki.python.org/moin/PythonVsPhp, "The vast majority of Python Web applications are run in a separate process. This has some important implications."
>
> From a PHP background, guess I just don't understand the concept of "separate processes".  What does this mean, how is it implemented, and what are the "important implications"?

This is talking about how PHP code is generally run inside the
server's process. I'll use Apache as my example, as that's what I have
handy.

There are a couple of ways that Apache can run PHP code. One is
spawning a new process for every page request, and using CGI mode; and
the other is a thing called mod_php, which runs PHP as a module inside
the Apache process. The first one gives great isolation between pages,
but it's horribly slow (every page request has to start a process -
cheap on Unix, expensive on Windows - and fully initialize PHP, which
is expensive everywhere); the second fixes the performance problem, at
the cost of maintaining hidden state in the Apache process. Most PHP
web sites out there are using (the equivalent of) mod_php. Coupled
with features like persistent database connections (another way of
improving performance at the cost of isolation), or changes to PHP
error handling configs, this can create *very* debug-hard problems
that depend on the exact distribution of work among Apache processes.
This becomes even worse if you have multiple PHP web sites running in
the same Apache instance; any one of them could interfere with any
other.

In contrast, Python code is run in a separate process from Apache. It
openly and honestly does NOT reset its state between page requests
(which you do need to be aware of; for instance, always commit/roll
back your database transactions before returning), but there's no way
for Python to affect Apache or vice versa. If you have two Python web
sites on the same server, they are completely isolated from each
other.

As well as the massively-beneficial implications of this isolation,
there are some less positive effects. One is that you need to have a
complete Python process for each site you have active - or else pay a
hefty startup penalty on first page load. This can cost a lot of
memory, especially if you have a lot of isolated little web sites
running. But the benefits of isolation are usually worth that cost;
it's possible to run the web server as one user (say, www-data) and
the application server as a different user (say, python-app), and then
grant file system permissions differently to the different users. You
could have two apps running in different versions of Python, or with
different versions of third-party packages. You can put memory or CPU
usage limits on the Python process, without worrying about the web
server itself going down.

It's a very different structure from the mod_php model, and worth
understanding. Personally, I think the costs are worth it; but if you
have a mostly-static web site with just a tiny amount of scripting in
it, it might be better to follow a PHP model.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 13:07 -0800
  Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 13:21 -0800
    Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 09:00 +1100
      Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 14:27 -0800
        Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 10:09 +1100
          Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 17:00 -0800
            Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 14:26 +1100
        Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 16:10 -0700
        Re: Understanding Python from a PHP coder's perspective Cameron Simpson <cs@zip.com.au> - 2015-12-08 10:07 +1100
        Re: Understanding Python from a PHP coder's perspective Tim Chase <python.list@tim.thechases.com> - 2015-12-07 21:11 -0600
        Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 14:47 +1100
  Re: Understanding Python from a PHP coder's perspective Cameron Simpson <cs@zip.com.au> - 2015-12-08 08:33 +1100
  Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 14:37 -0700
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 08:40 +1100
  Re: Understanding Python from a PHP coder's perspective Terry Reedy <tjreedy@udel.edu> - 2015-12-07 16:53 -0500
  Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 14:59 -0700
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 09:03 +1100
  Re: Understanding Python from a PHP coder's perspective Tim Chase <python.list@tim.thechases.com> - 2015-12-07 16:28 -0600
  Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 20:11 -0800
  Re: Understanding Python from a PHP coder's perspective Peter Otten <__peter__@web.de> - 2015-12-08 10:24 +0100
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 20:40 +1100

csiph-web