r/programming • • Feb 24 '13

Ruby 2.0.0

http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/
600 Upvotes

193 comments sorted by

View all comments

Show parent comments

10

u/TikiTDO Feb 24 '13 edited Feb 24 '13

Now let's note get carried away here. PHP has a perfectly capable standalone interpreter which allows you to do anything you would want in a scripting language. I've written some threading server apps in PHP for the hell of it, and my only complaints there were syntax related. There are even tools to compile PHP to bytecode.

Ruby is great if you want a language that's pretty simple to pick up, without too many caveats until you get really deep into the guts of the environment. It's not the most efficient language out there, but with support for C plugins even that can be addressed for most situations. I wouldn't use it for very performance critical operations, but it's a good choice for general coding, and particularly good for prototyping.

4

u/[deleted] Feb 24 '13

I've written some threading server apps in PHP

Is any of your code publically available? I'd be curious to see how that works.

1

u/TikiTDO Feb 24 '13 edited Feb 24 '13

I'll see if I can find it, but this was a small proof of concept project I did years ago just to see if it was possible (Open multiple connections, then echo text typed in one to all the others), so it's probably in some archive in a deep corner of my backup drive.

More specifically, the program was actually multi-process, not multi-threaded. I remember abusing shared memory, and generally doing things that most would not associate with PHP in order to overcome the limitations of the language. I also recall that I had a busy loop for some reason, and that the server broke my networking if I didn't shut it down properly, though that was just me being lazy with connection management. These days I think they've implemented proper native threading in PHP, so I imagine you could do what I did back then with significantly less hackery.

2

u/[deleted] Feb 24 '13

These days I think they've implemented proper native threading in PHP

That's the part I'm interested in. I didn't think it was possible to do true multithreading in PHP.

1

u/TikiTDO Feb 24 '13

Take a look at PHP pthread.

1

u/[deleted] Feb 24 '13

Unfortunately, pthread is POSIX-only so you can't use it if you want your code to be portable to non-POSIX operating systems (i.e. Windows).

1

u/TikiTDO Feb 25 '13

It seems there is even a Windows release of PHP pthreads which likely relies on Windows threading. It's still not a good reason to build a serious cross-platform server app in PHP, but it's certainly possible.

0

u/Moocat87 Feb 24 '13

I think the best distinction to draw is that Ruby is an object oriented programming language while PHP is a scripting language. Yes, you can do whatever you want in either, but each has its very distinct strengths. Ruby is closer in purpose to C/C++, upon which operating systems are built, than PHP, which lives in scriptland with shell scripting languages. You wouldn't usually pick PHP to write a back-end. Ruby, definitely. And with Rails, it can be your front-end too.