python - Why would one use accelerators with fastcgi for PHP?


I'm a newbie to web technology, and still on a learning curve. Heard that, fastcgi would keep the compiled(interpreted) php code in memory, so why would one has to use op-code caching (apc or eaccelerators) for PHP? But I never heard of any such accelerators for Python. I'd expect as python and php are both interpreted language, it makes me think that, there has to be a room for python accelerators ? pls correct me if I'm wrong.

Many thanks




PHP on its forgets a just-in-time compilation as soon as it has done with that file. This means PHP has to recompile the file every time it wants something from it. An OpCode cache (like you're talking about side-steps this and keeps PHP classes compiled in memory for a predetermined time).

Python on the other hand natively compiles things down a much faster interpretable code on their first run. You see all the.pyc files around your project, they're equivalent to PHP's OpCode.

PHP OpCode caches often bundle in other features (memory-resident data stores) and these are also provided out-the-box by Python.

There are a couple of "accelerators" for Python though. The most notable is Psyco that claims a "2x to 100x" speed improvement in ideal conditions. But this comes at a monstrously heavy cost of RAM and it only runs on i386 archs.




Unlike PHP, (C)Python does not throw the bytecode away after running it. When is imported and there is no module.pyc, it is bytecode-compiled and the result is copied to module.pyc; is it already exists, compilation is skipped and the ready-made module.pyc is used. One can do the same thing for the main script manually, too.

As for

fastcgi would keep the compiled(interpreted) php code in memory, so why would one has to use op-code caching (apc or eaccelerators) for PHP?

I never head of this - FastCGI doesn't start a new process for each request (as opposed to plain old CGI, which starts basically starts the interpreter as a new process), but that's it. This benchmark shows that FastCGI doesn't perform any better than mod_php (i.e. interpreter embedded in the Apache process).




Python is compiled to bytecode when executed (the .pyc files), and the bytecode is kept around, not discarded. The compiled python is used instead of the source if it is present. Therefore, there is no need for additional opcode caching in python as it is already built in.

People are also looking for solutions to the problem: PHP - Parse template variable with regex


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.