The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

RoR + PHP ?

I know that some of you might wonder WHY? but the question still is: Can RoR work together with PHP. The case: Some things developed in PHP and we would like to start working with Ruby and build things on top of it. Can it be done? Any good resources for that?

Yea, as well as webservices (which do incur a bit of an overhead with all the overhead what parsing XML etc), you can also have Ruby and PHP installed on the same machine, and simply use php for certain requests, and RoR for others, and simply share the the DB. I would assume that with Lighttpd that you can place php files in the ./public/ folder and let FCGI process them.

Sharing a database seems pretty straightforward, as does putting php files into the public directory. Are you worried about how to use the same sessions between two languages? That strikes me as potentially the trickiest part.

Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

Yea, sessions are a pain, I forgot about that. My way to approach that is to again use the DB. However, I must say, I would try and where possible maybe work on things in a away so that one one of the two languages is needing sessions if I could. I'm not too keen on the cookies idea. Cookies are resitricted by size and have some security issues

Well I haven't done it my self, I'm just assuming that is possible based on my knowledge of how FCGi/ Lighttpd / PHP / Rails works.

I do know if you wanna use FCGI in PHP, you'll need to tell it in configure using --enable-fcgi I think. You'll know if your PHP binary is FCGI compatible when you do a php -v as it will say fcgi as well as cli.

When using either FCGI or CGI, you do need to be careful, certainly in CGI mode, PHP doesn't have all the environment variables and other similar vars that you sometimes find under Apache's mod_PHP. I can't remember the exact differences are, but I am aware it might be a gottcha if you have assumed certain variables exist say in the environment etc.

Basically, if you get FCGI/PHP working under Lighttpd, there's no reason why you can't put PHP scripts in the ./public folder of your rails project. As others have suggested, sessions are also a catch.

The real question is, integration with legacy apps aside, why would you want to use PHP as well as RoR?

Including legacy apps, this situation reminded me of the story of the guy who wanted to try out Rails, so he attempted to rewrite the Java app he had been working on for 6 months with Rails. Four days later, most of it was done.

Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

Including legacy apps, this situation reminded me of the story of the guy who wanted to try out Rails, so he attempted to rewrite the Java app he had been working on for 6 months with Rails. Four days later, most of it was done.

Interesting that you said that. We were debating about Java vs. Ruby and how Java is moving ahead in may ways. Do you remember where you read that story about that guy?

basically I see such php+RoR need in projects that
- lack RoR programmers , so certain modules are built with php
- RoR lacks certain features that are available in php, which natural because of maturity

As for Java vs RoR story, might be true if he never judged the result quality and scalability. And.. if he did Java the hard way .. These days JSF itself saves tons of time, not to mention a lot of RAD tools already available.

Including legacy apps, this situation reminded me of the story of the guy who wanted to try out Rails, so he attempted to rewrite the Java app he had been working on for 6 months with Rails. Four days later, most of it was done.

basically I see such php+RoR need in projects that
- lack RoR programmers , so certain modules are built with php
- RoR lacks certain features that are available in php, which natural because of maturity

Building some of your app in RoR and some in PHP sounds like a complete maintenance and interoperability nightmare. If you need more RoR programmers hire them, or get the PHP guys to learn it. If they any good it shouldn't take them more than a week or two to get up and running with at least the basics of Rails and Ruby, and they'll learn more as the project goes along. Bottom line when it comes to mixing PHP/RoR in this way, my advice...don't do it. Pick a platform and stick to it, or you'll regret it.

Regarding your second point, name those features otherwise its not really an argument. I can't think of anything I've been doing in Rails when I've thought, "damn I wish it had xxxx like PHP". Ruby libraries are fewer in number, but higher in quality, I've found.

This reminds me very much when we first started looking at Rails in my old job. Certainly one of the options we thought about was migrating a PHP app slowly to Rails. In the end, while it was a bit of a nightmare for a few weeks, it was well woth just moving the whole thing to Rails in one go; in the long run it saved a lot of hassle.

Though I've been riding the Rails for a while now, I think PHP still has some use in writing quick 'n dirty "throw-away" web scripts for which Rails would simply be overkill.

However, the new Camping Microframework for Ruby may balance things out a bit. It's a sort of micro-Rails, and while I haven't had a chance to try it out yet, it looks darned impressive for situations where you need a script up and running in an hour, and don't want to play around with FastCGI deployments etc.

I think even DHH will even agree here that, PHP still has a role. As Arto suggested, PHP does seem to work well in situations where you want simple disposable code, and you know for certain that the site will not need to evolve into anything complex.

The thing where PHP comes in handy is with sites with lots of static content, and maybe the odd contact form mailer. However, saying that, PHP as a language is a lot heavier than Ruby, and probably less functional imo