PHP & Ruby -- Rendered to One Page


I’ve been looking through these boards and the Internet at large for
the last few hours trying to determine if it’s possible to render a
single page that has both PHP and Ruby elements in it. Specifically,
I am setting up a RoR site, but there are a couple pre-made PHP
modules I’ve found that could handle code we would otherwise have to
write from scratch in RoR, so I would like to incorporate these
modules into a few pages alongside the RoR elements (yes, I know
managing the sessions, etc. will be a pain). While there is a wealth
of information about setting up a single server that can serve both
PHP and RoR pages, these seems to be little that discussion about the
possibility of a single page request running both PHP and RoR code?

Does anyone know if this is possible, and how? Performance is a
consideration, as I am trying to create a page that gets users real
time information.

Thanks for any help,

Have you looked stuff about invoking command line programs from with
rails? That way you might be able to call the php interpreter and get
the result as text.

Also, have you checked if their are any ruby gems that do what the php
libraries do?

What is so important in PHP that you cannot possibly spend time
converting it into Ruby?

Hi Bill,

I combined Typo3 as a CMS and several Railsprojects.
The best solution for me, is to grab the page, what I need.
I do that with open-uri and hpricot.
Take a look @

May be, this could be a solution for you?
What do you want to do exactly?



Rafael wrote:



Hi Rafael

That sounds interesting, but doesn’t that increase the network data
transfer for your application and then possibly have an impact on the
performance? If I understand what you say, you have multiple
applications running simultaneously (on different ports/ directories)
and then use hpricot to get the results from the views of these other
projects (Typo) and display them on the output of your Rails app?

Could you share more details? It does sound interesting…

6/25/2007 | 4:54 PM.

Hm, I would have thought PHP included in a view would be interpreted.
That’s probably a stupid notion and apparently untrue.

Yes sure, may be you’re interested why my thoughts to combine.
IMHO, at the moment, there isn’t either an Enterprise Rails CMS nor it
wont be.
Typo3 is serving all our needs in a normal Webproject - Day, but what
when I want to make a nice webapp?
That’s where RoR comes in :slight_smile:
I like Ruby AND Rails much more then PHP and PHP MVC solutions, what
I’ve seen.

I went quite long for this solution. Finally its quite easy, but you
have to consider somethings:

  • You have to have is full access to your webserver, because, shared
    hosting is not nice here.
  • Best is running the Typo3 CMS or lets say, the PHP on the same
  • To increase performance, you can cache or generate the page you

A) Performance
I think performance is absolutely ok, the page which comes out from
typo3 is cached at the moment
May you want to take a look:

B) Integration
I go with a apache mod_proxy solution
I have a balancer/cluster with 3 Mongrel instances started.
the mod proxy roule takes the name of the html from typo3 and
translates it to the rails route.

What you think? May be you have also some ideas, how to go further?
At the moment this solution is more or less temporary, it works but I
really want to optimize it.



Rafael wrote:

have to consider somethings:
typo3 is cached at the moment
What you think? May be you have also some ideas, how to go further?
At the moment this solution is more or less temporary, it works but I
really want to optimize it.



Hi Rafael,

Thanks for the information - it does sound interesting. I am thinking
of something similar but haven’t yet been able to decide which way to
go. I do quite like Radiant and that may be the CMS behind the site.
There is also a project called RadiantOnRails which aims to allow easier
integration by making it a plugin.

Let’s see which way it goes!

6/27/2007 | 9:22 AM.

Another possibility might be to use JRuby to run your rails app, and
Quercus to run the PHP. Both can be deployed to an application server
as Java WARs (web archives). In this scenario, your Rails app and PHP
app are both running as separate servlets. When your Rails app invokes
a URL on the PHP app, I believe that the communication is handled
directly by the application server.

// Gregory