# Rails and PHP

**URL:** <https://www.ruby-forum.com/t/rails-and-php/75435>\
**Category:** Rails\
**Created:** [November 9, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435 "2006-11-09T21:26:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/1 "2006-11-09T21:26:22Z")

</div>

Starting a new thread since I have a new question.  
Plan is to have Rails as the web services server and PHP as client.

What I’m trying to figure out is at one point in the request does  
“respond\_to” know when it’s being called.

Example, I have a state controller, with a list action:  
StateController:  
def list  
@state = State.find\_all  
respond\_to do |wants|  
wants.html  
wants.xml { render :xml =\> @state.to\_xml}  
end

Now the php makes a request to the server (using REST) via curl -

$request = ‘[http://myrailsserver](http://myrailsserver) &  
query=’.urlencode(‘state/list).’&results=8’;

$session = curl\_init($request);

So this establishes the curl session. What I want to do is create a  
conditional statement based on  
the request coming in and Rails acting. I am trying not to send data  
back  
to php.

I know this is probably an insane question.  
I do hope someone answers and knows something.

Stuart

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 9, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/2 "2006-11-09T21:38:24Z")

</div>

On 11/9/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> @state = State.find_all
> 
> ```
> 
> So this establishes the curl session. What I want to do is create a  
> conditional statement based on  
> the request coming in and Rails acting. I am trying not to send data back  
> to php.
> 
> I know this is probably an insane question.  
> I do hope someone answers and knows something.

I’m not sure what the question is, but GET /state/list.xml?results=8 so  
respond\_to knows to use the .xml block.

jeremy

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 9:13pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/3 "2006-11-10T21:13:27Z")

</div>

On Nov 10, 2006, at 4:55 AM, Dark A. wrote:

> Another possibility which I read about on a thread at ruby-  
> [forum.com](http://forum.com) has some php pages living in side the Rails app’s public  
> directory. It was suggested as one possibility that you could use  
> sub-domains for the php.
> 
> In my case though I wonder if I could use sub-domains for Rails ?  
> For example , the link in the PHP menu might be  
> [www.mydomain.com/users](http://www.mydomain.com/users) . This would re-direct(?) to the Rails app .
> 
> Stuart

Hey Stuart-

```
I had to deal with this problem about a year and a half ago when i

```

built the [yakimaherald.com](http://yakimaherald.com) website. There were still some php scripts  
that were in use that weren’t worth rewriting at the time. The way I  
did it was to have lighty setup like a normal rails/fcgi  
configuration. And then tell lighty to also run any php scripts that  
it find in /public. This works fine for simple integration stuff.

```
You could do the same thing now with apache2.2 and mod-proxy-

```

balancer. Just use the normal mongrel setup for the apache vhost and  
add the php handler in as well. Then any call to a url that ends  
in .php will serve the php page directly as long as its in public.

```
It's all a bit fugly but it can be done.

```

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/4 "2006-11-10T13:56:09Z")

</div>

On 11/10/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yet I read here: [http://www.almaer.com/blog/archives/001178.html](http://www.almaer.com/blog/archives/001178.html) in  
> particular this paragraph:
> 
> _Migration via ‘Portal’_  
> The PHP front end can also proxy through to the Rails applications running  
> behind the scenes. This makes the app feel a little like a portal, but  
> basically it is just a proxy. The front end can build the template (header,  
> footer, sidebars) and then call back to the Rails backend to get the main  
> content.  
> Either I"m missing something in what I’ve been told so far and read or  
> maybe I’m misinterpreting this article.

Another possibility which I read about on a thread at [ruby-forum.com](http://ruby-forum.com)  
has  
some php pages living in side the Rails app’s public directory. It was  
suggested as one possibility that you could use sub-domains for the php.

In my case though I wonder if I could use sub-domains for Rails ? For  
example , the link in the PHP menu might be  
[www.mydomain.com/users](http://www.mydomain.com/users) . This would re-direct(?) to the Rails app .

Stuart

> > > What I’m trying to figure out is at one point in the request does
> 
> –  
> [Dark ambient - Wikipedia](http://en.wikipedia.org/wiki/Dark_ambient)

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/5 "2006-11-10T21:47:31Z")

</div>

On 11/10/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > In my case though I wonder if I could use sub-domains for Rails ?  
> > did it was to have lighty setup like a normal rails/fcgi  
> > configuration. And then tell lighty to also run any php scripts that  
> > it find in /public. This works fine for simple integration stuff.
> 
> ```
> You could do the same thing now with apache2.2 and mod-proxy-
> 
> ```
> 
> balancer. Just use the normal mongrel setup for the apache vhost and  
> add the php handler in as well. Then any call to a url that ends  
> in .php will serve the php page directly as long as its in public.
> 
> ```
> It's all a bit fugly but it can be done.
> 
> ```

public Rails public ? What if there are subdirectories. This has  
numerous  
directories for php

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 10:13pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/6 "2006-11-10T22:13:34Z")

</div>

public Rails public ? What if there are subdirectories. This has  
numerous directories for php

That wont work.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 12:13pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/7 "2006-11-10T12:13:55Z")

</div>

The question is really a way on how I can NOT have php pulling the data  
and  
delivering it but have PHP call into Rails and letting Rails takeover  
delivering either a form to create a query and then rendering the  
results ,  
or rendering the results from a table.

Everything I’ve read and heard so far is that either using Rails as a  
proxy  
or using Web services, Rails sends the data requested back to PHP and  
then  
it’s up to PHP to format and return the data for presentation.

Yet I read here: [http://www.almaer.com/blog/archives/001178.html](http://www.almaer.com/blog/archives/001178.html) in  
particular this paragraph:

_Migration via ‘Portal’_  
The PHP front end can also proxy through to the Rails applications  
running  
behind the scenes. This makes the app feel a little like a portal, but  
basically it is just a proxy. The front end can build the template  
(header,  
footer, sidebars) and then call back to the Rails backend to get the  
main  
content.  
Either I"m missing something in what I’ve been told so far and read or  
maybe  
I’m misinterpreting this article.

Stuart

On 11/9/06, Jeremy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > StateController:
> 
> I’m not sure what the question is, but GET /state/list.xml?results=8 so  
> respond\_to knows to use the .xml block.
> 
> jeremy
> 
> >

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/8 "2006-11-10T22:27:37Z")

</div>

On Nov 10, 2006, at 12:46 PM, Dark A. wrote:

> ```
> It's all a bit fugly but it can be done.
> 
> ```
> 
> public Rails public ? What if there are subdirectories. This has  
> numerous directories for php
> 
> Stuart

```
Subdirectories are fine. You just need to have the front end

```

webserver always look for static files first before it send the  
request to mongrel. If there is a static file with .php ext apache  
will interpret the php and send it out. So yes it has to be in public  
but it can be nested directories inside public. Its pretty nasty  
though when you get a big mix of php code in your public dir.

```
The other side effect of this is that to make the php files work

```

with this method, the url always has to have the full url to the php  
file including the .php ext.

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [November 10, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/rails-and-php/75435/9 "2006-11-10T22:17:35Z")

</div>

On 11/10/06, Mark A. Turner [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> public Rails public ? What if there are subdirectories. This has numerous  
> directories for php
> 
> That wont work.

Okay thank you. So then back to my original question. What if Rails  
exists  
as a sub - domain and certain pages are invoked via links in the PHP  
site ?

Stuart

> 

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...
