Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I originally posted this on StackOverflow and it was suggested that I try posting this here because, "It might be something like the configuration in CGI is different than the configuration for your user."

Having said that, here is my original post:

Admittedly, this is a strange problem for me to have, but here is what I'm doing:

I've got a Ruby script that is executing a string of PHP code and capturing the output.

This is somewhat related to another problem that I had with running cgi PHP from the command line.

Here is the Ruby script's source:

#!/usr/bin/ruby
puts "Content-type: text/html\n\n"
puts "Start PHP Output<br />"
puts `echo '<?php echo "hello world"; ?>' | php5 -q`
puts "End PHP Output<br />"

The really odd thing that I can't figure out is that the PHP code here seems to behave differently when I run the Ruby script from the command line vs. from CGI. Which really doesn't make sense to me, because either way I'm executing the same string of PHP from the command with the same arguments.

When I run the above Ruby script from the command line, I get the output that I expect:

Content-type: text/html

Start PHP Output
hello world End PHP Output

When I hit that same Ruby script from a browser via CGI, I get this output:

Start PHP Output
X-Powered-By: PHP/5.2.13 Content-type: text/html
puts "Content-type: text/html\n\n" puts "Start PHP Output
" puts echo 'hello world' | php5 -q puts "End PHP Output
" End PHP Output

It looks, to me, like what is happening is that the string of PHP is not suppressing the headers, like I would expect the -q option to do... and is also dumping my entire Ruby script back to the browser - which baffles me.

Any thoughts?

Thanks in advance!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I was able to get a solution on StackOverflow. Check it out here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.