Speakin of the Devil


#1

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.


#2

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…


#3

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…


#4

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…


#5

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


http://mongrel.rubyforge.org/


#6

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

#7

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.