Executing php snippets

With the following method, I am able to execute and display a php page:

def phpstuff
require ‘net/http’
url = URI.parse(‘http://127.0.0.1/phpstuff.php’)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
render_text res.body
end

However, let’s suppose I want to simply execute a snippet of php code.
If I am just running straight out of mongrel, on say port 3000 (not
through apache), how can do that? Can I do it in the rhtml somehow?

Also, is there way, from within Rails, to get back a value returned,
say, by executing a method in php? Thanks, Ike

On Tue, 19 Dec 2006, Ike wrote:

 render_text res.body

end

However, let’s suppose I want to simply execute a snippet of php code.
If I am just running straight out of mongrel, on say port 3000 (not
through apache), how can do that? Can I do it in the rhtml somehow?

Also, is there way, from within Rails, to get back a value returned,
say, by executing a method in php? Thanks, Ike

% php -r ‘print(“hello world\n”);’
hello world

If you can call php via the CLI then that would work… kind of ugly,
but
it would work. You can also just pass it a filename to execute and then
parse the results inside of Rails to do whatever you need to do.

-philip