tags:

views:

183

answers:

5

I am creating a web application which requires threading and I am trying to figure out which langauge between PHP and Ruby has better threading functionality and better performance.

Even if not in built, some easy work arounds or add-ons.

+2  A: 

PHP does not normally do threading.

Peter Lindqvist
+9  A: 

I would have to say Ruby, since Ruby actually supports it. PHP does not.

With PHP, you can create new processes (which is a bad idea) or write multiple web services and use curl_multi_* functions to accomplish some things, but threading is not a feature of PHP.

Lucas Oman
So basically, my web app needs to run a few thousand queries in 5 mins in the background. I cannot run this from one thread because one thread will only run about a fourth of the queries that I need and the time period cannot be more than 5 mins hence need threading. What do you think?
Aceacer
Why do web apps run background processing?
Peter Lindqvist
Apologies about my terminology but basically my application consists of the front-end and this background processing module.
Aceacer
+2  A: 

PHP does not have threading (good thing IMO).

Ruby has, but in 1.8 it has green threads, where in 1.9 it has a GIL. What this means (in the case of MRI and YARV - the 1.8 and 1.9 main Ruby implementations) is that 2 threads cannot run at the same time (in both cases) and you can't take advantage of multi-core processors.

You can use processes in both languages to overcome those limitations.

Emil Ivanov
It is not true that green threads can't take advantage of multi-core processors. Counterexamples are Erlang and MzScheme, among many others. It is also not true that Ruby 1.8 has green threads. There is nothing in the Ruby Specification that forces a Ruby Implementation to use green threads, and indeed, all Ruby 1.8 implementations except one use native threads. And it is not true that Ruby 1.9 has a GIL. Again, there is nothing in the Ruby Spec that forces implementations to have a GIL and most of them don't.
Jörg W Mittag
Jörg - correct! When I was talking about Ruby I generally meant MRI (JRuby has proper threading support).
Emil Ivanov
+2  A: 

PHP currently has no support for the explicit use of threads; your PHP server may or may not use threads to serve different HTTP request ( the Zend engine does, I believe), but there are no facilities to create or coordinate threads via PHP code.

Michael Borgwardt
+5  A: 

These are probably the two worst languages to choose if you want threading, but if you really want one of these two, I guess Ruby can do it. Better go with JRuby, though. The JVM does very excellent threading.

(Or go with Groovy, which is basically Java with lots of Rubyisms.)

mcv