# PHP & Ruby -- Rendered to One Page

**URL:** <https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675>\
**Category:** Rails\
**Created:** [June 25, 2007, 7:44am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675 "2007-06-25T07:44:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 7:44am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/1 "2007-06-25T07:44:11Z")

</div>

All,

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,  
Bill

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 8:12am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/2 "2007-06-25T08:12:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 9:33am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/3 "2007-06-25T09:33:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 10:46am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/4 "2007-06-25T10:46:52Z")

</div>

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 @ [http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)

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

regards

Rafael

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 10:54am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/5 "2007-06-25T10:54:53Z")

</div>

Rafael wrote:

> regards
> 
> Rafael

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…

Cheers,  
Mohit.  
6/25/2007 | 4:54 PM.

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 10:53am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/6 "2007-06-25T10:53:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 25, 2007, 11:20am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/7 "2007-06-25T11:20:02Z")

</div>

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 🙂  
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  
server
- To increase performance, you can cache or generate the page you  
parse

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:  
[http://www.ella.org/kontaktboerse.html](http://www.ella.org/kontaktboerse.html)

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.

regards

Rafael

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 27, 2007, 3:23am UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/8 "2007-06-27T03:23:58Z")

</div>

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.
> 
> regards
> 
> Rafael

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!

Cheers,  
Mohit.  
6/27/2007 | 9:22 AM.

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [June 27, 2007, 8:02pm UTC](https://www.ruby-forum.com/t/php-ruby-rendered-to-one-page/107675/9 "2007-06-27T20:02:38Z")

</div>

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
