4

Currently I'm considering between these 3 languages for a project that will require a very high uptime (uptime is more important than performance).

I've been a PHP developer for some time and wouldn't mind switching to a "better" language such as Python or more (possibly) more professional such as Java but there is one thing holding me back:

In PHP suppose one user creates some malformed/strange request that causes my code to crash - only that single user will be affected. Other users can continue making requests since each HTTP request invokes a new PHP process.

Consider Python or Java: if a user crashes my backend code, there is only a single process running and the entire webapp goes down which would be a disaster.

My question is, is there a word that describes these two different approaches to web programming? Also, am I missing anything obvious, or does PHP really have this great of an advantage over Python/Java/other persistent process approaches and if so, why doesn't Python adopt this approach?

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
  • 1
    This seems more like a server architecture problem than a language problem. (Though maybe I'm wrong; I've never had to design a server.) – Waleed Khan Aug 28 '12 at 04:04
  • 1
    How would a malformed request make everything crash? – ChocoDeveloper Aug 28 '12 at 04:13
  • @ChocoDeveloper: I'm assuming that Python/Java has a single process serving all requests, so if that single process goes down then so does everything else.. – Martin Konecny Aug 28 '12 at 04:36
  • @ChocoDeveloper if a malformed request crash everything, there must be a terrible bug inside the framework that is used. it may happen... but i think this is extremely seldom and tough it should have a very low impact in the decision of which technology to use... except you try to invent the wheel once again ;-) – jfried Aug 28 '12 at 18:49

2 Answers2

1

What I was looking for was someone to point me to an article like this:

http://www.electricmonk.nl/docs/apache_fastcgi_python/apache_fastcgi_python.html

Python can run persistently in the background via WSGI, and there can be many interpreteres waiting for a request. If one of the interpreters crashes, this is not a problem as other interpreteres are waiting, and because Apache can automatically restart any interpreter that crashes.

Python can also be invoked manually on every request similar to PHP, but this is slower.

Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
0

This is not a language specific problem. This is a problem how you test your software before you put it into your live environment. And how you desgin your server infrastructure.

If you have a bug in your Software that crashes the server you should fix it. Even PHP can crash the complete server if there is a strange bug in mod_php/your code.

If you don't want to have a single point of failure you must build a high availability setup. at least 2 Loadbalancers (for example with keepalived), 2 Webservers, 2 Databaseservers, 2 ...

Also you want to use something like God or mon to monitor your processes and to react on sudden death of needed services.

jfried
  • 505
  • 2
  • 5
  • "If you have a bug in your Software that crashes the server you should fix it. Even PHP can crash the complete server if there is a strange bug in mod_php/your code." Of course I should fix it. But you talk as if bugs are completely avoidable. I'd like to go the route where the impact of a bug can be minimized. – Martin Konecny Aug 28 '12 at 16:35
  • @MartinKonecny if you use apache with mod_php you must use mpm-prefork, this is slow (compared with other workers). with python you can also use mod_wsgi wich apache, if you want with the slower mpm-prefork (like php, same "crash" behavior) or use daemon mode. This is like FASTCGI for PHP. And yes, if a FASTCGI Process dies, Apache will start a new one automatically on the next request. (for php, for python, ...). You could also use other Servers like Tornado, Twisted, and a dozen others. Every one with its own threading model. On the other side java has an extremly good Exception handling... – jfried Aug 28 '12 at 18:44
  • Perhaps I should have mentioned specific technologies. Apache + mod_php + Zend Framework seems to be the most popular for PHP, Django for Python and Tomcat for Java. – Martin Konecny Aug 29 '12 at 00:49