# Speakin of the Devil

**URL:** <https://www.ruby-forum.com/t/speakin-of-the-devil/95563>\
**Category:** Rails\
**Created:** [June 6, 2006, 10:56am UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563 "2006-06-06T10:56:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 6, 2006, 10:56am UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/1 "2006-06-06T10:56:10Z")

</div>

Hi.

How can one embed PHP into their rhtml files (located in the views  
folder?

I’d like to use those JD library graphical plugs that use PHP…

I’ve already added .rhtml to the php extension in apache’s httpConfig…

Insights or the truth would be appriciated.

Dominic S.

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 6, 2006, 12:02pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/2 "2006-06-06T12:02:00Z")

</div>

> I’ve already added .rhtml to the php extension in apache’s httpConfig…

what did you think this would do? besides confuse apache even more??

> How can one embed PHP into their rhtml files (located in the views  
> folder?

your best bet is to not embed php in a rhtml file, but to embed it in a  
php file, and designate a subdir to use the php interpreter. eg, with  
lighttpd:

server.document-root = “/var/www/railsapp/public/”  
server.error-handler-404 = “/dispatch.fcgi”  
fastcgi.server = ( “.fcgi” =\>  
( “localhost” =\>  
(  
“min-procs” =\> 1,  
“max-procs” =\> 1,  
“socket” =\> “/var/www/railsapp/log/fcgi.socket”,  
“bin-path” =\> “/var/www/railsapp/public/dispatch.fcgi”,  
“bin-environment” =\> ( “RAILS\_ENV” =\> “development” )  
)  
)  
)

$HTTP[“url”] =~ “^/php” {  
server.document-root = “/var/www/php/”  
alias.url = ( “/php/” =\> “/var/www/php/” )  
fastcgi.server = ( “.php” =\>  
( “localhost” =\>  
(  
“bin-path” =\> “/usr/bin/php-cgi -c /etc/php.ini”,  
“bin-environment” =\> (  
“PHP\_FCGI\_CHILDREN” =\> “1”,  
“PHP\_FCGI\_MAX\_REQUESTS” =\> “32”  
),  
“socket” =\> “/tmp/php.socket”  
)  
)  
)  
}

or you just want to be messy and throw your php files in public/ you  
could remove the $HTTP[“url”] =~ “^/php” { and the two lines below it.  
im sure apache can do all this…i switched to lighttpd for the concise  
and simple configuration. the better performance is just gravy…

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 6, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/3 "2006-06-06T12:05:15Z")

</div>

> How can one embed PHP into their rhtml files (located in the views  
> folder?

popen() the php interpreter in your view, and display the results  
inline. but thats pretty nasty if you ask me…

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 6, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/4 "2006-06-06T22:54:58Z")

</div>

It is quite nasty. And if nasty, violates Ruby philosophy.

So beware Ruby writers, it’s possible to say if you embed in Ruby, you  
may not be programming in Ruby anymore.

; )

Dominic S.

carmen wrote:

> > How can one embed PHP into their rhtml files (located in the views  
> > folder?
> 
> popen() the php interpreter in your view, and display the results  
> inline. but thats pretty nasty if you ask me…

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 7, 2006, 12:04pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/5 "2006-06-07T12:04:23Z")

</div>

On Tue, 2006-06-06 at 12:05 +0200, carmen wrote:

> > How can one embed PHP into their rhtml files (located in the views  
> > folder?
> 
> popen() the php interpreter in your view, and display the results  
> inline. but thats pretty nasty if you ask me…

No, don’t do this. popen() in ruby has very weird issues and will cause  
you mountains of problems. The #1, #2, and #3 thing that seems to cause  
Rails apps to slow or stop is popen.

–  
Zed A. Shaw

> **[Zed A. shaw](https://zedshaw.com/)**
>
> Personal essays and writings by Zed A. Shaw.

[http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 7, 2006, 12:24pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/6 "2006-06-07T12:24:35Z")

</div>

On Tue, Jun 06, 2006 at 10:56:10AM +0200, Dominic S. wrote:

> How can one embed PHP into their rhtml files (located in the views  
> folder?
> 
> I’d like to use those JD library graphical plugs that use PHP…
> 
> I’ve already added .rhtml to the php extension in apache’s httpConfig…

That’s not going to work, as the rhtml file gets interpreted by the  
Rails  
dispatcher, not Apache. The only thing I can think of is to invoke the  
PHP  
interpreter inside of Rails, but the resulting tentacles are your own  
problem.

For image generation, though, you don’t need to run PHP inside of Rails,  
you  
just need to point your image src= at the PHP script. But I don’t know  
anything about these “JD library graphical plugs”, so maybe you do need  
PHP  
inside your HTML.

- Matt

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 7, 2006, 3:39pm UTC](https://www.ruby-forum.com/t/speakin-of-the-devil/95563/7 "2006-06-07T15:39:01Z")

</div>

Put the php page in another folder as suggested above and use Ruby’s  
net/http library to make the request to your server. This allows yo  
uto store this into a string which you can then parse and embed.

Or look for Ruby/Rails based solutions for your problem.
