Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP vs. long-running process (Python, Java, etc.)?

Tags:

I'd like to have your opinion about writing web apps in PHP vs. a long-running process using tools such as Django or Turbogears for Python.

As far as I know: - In PHP, pages are fetched from the hard-disk every time (although I assume the OS keeps files in RAM for a while after they've been accessed) - Pages are recompiled into opcode every time (although tools from eg. Zend can keep a compiled version in RAM) - Fetching pages every time means reading global and session data every time, and re-opening connections to the DB

So, I guess PHP makes sense on a shared server (multiple sites sharing the same host) to run apps with moderate use, while a long-running process offers higher performance with apps that run on a dedicated server and are under heavy use?

Thanks for any feedback.

like image 594
user73669 Avatar asked Mar 12 '09 16:03

user73669


People also ask

What is the difference between PHP and Python?

PHP is based on object-oriented programming whereas Python is both object-oriented and procedure-oriented programming. Python is a general-purpose programming language used for backend web development. On the other hand, PHP is not designed for general-purpose programming it is only used for backend web development.

What is faster Python or PHP?

Each time a file is created or modified; Python converts the code into bytecode. This code compilation method makes Python quicker than PHP. PHP programmers can simply improve the speed of PHP applications by installing a variety of caching systems. By default, Python is a faster language.

Which is better Python or PHP?

Python is better in long-term projects. PHP has a very low learning curve, and it is straightforward to get started with. Python uses indentation enforcements that are quite strict. This makes it more readable than PHP.

Which is more secure PHP or Python?

Python is more secure than PHP. It has many security features that you can leverage to build complex applications with high-end functionality and clear goals.


2 Answers

After you apply memcache, opcode caching, and connection pooling, the only real difference between PHP and other options is that PHP is short-lived, processed based, while other options are, typically, long-lived multithreaded based.

The advantage PHP has is that its dirt simple to write scripts. You don't have to worry about memory management (its always released at the end of the request), and you don't have to worry about concurrency very much.

The major disadvantage, I can see anyways, is that some more advanced (sometimes crazier?) things are harder: pre-computing results, warming caches, reusing existing data, request prioritizing, and asynchronous programming. I'm sure people can think of many more.

Most of the time, though, those disadvantages aren't a big deal. You can scale by adding more machines and using more caching. The average web developer doesn't need to worry about concurrency control or memory management, so taking the minuscule hit from removing them isn't a big deal.

like image 64
Richard Levasseur Avatar answered Sep 30 '22 17:09

Richard Levasseur


  • With APC, which is soon to be included by default in PHP compiled bytecode is kept in RAM.
  • With mod_php, which is the most popular way to use PHP, the PHP interpreter stays in web server's memory.
  • With APC data store or memcache, you can have persistent objects in RAM instead of for example always creating them all anew by fetching data from DB.

In real life deployment you'd use all of above.

like image 39
vartec Avatar answered Sep 30 '22 17:09

vartec