Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 837815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:12:14+00:00 2026-05-15T05:12:14+00:00

Admittedly, this is a strange problem for me to have, but here is what

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:12:15+00:00Added an answer on May 15, 2026 at 5:12 am

    As far as I can tell, PHP takes over the entire request & reruns it with the same file asked for, after which it returns control to ruby at the point of invocation. Please us the CLI instead of the CGI if possible if this is what you’re trying to do with it.

    You could try to clear up the environmental variables by which the cgi determines it’s in a webserver request.

    #!/usr/bin/ruby
    puts "Content-type: text/plain\n\n"
    puts "Start PHP Output<br />"
    f = IO.popen("env -i php5-cgi -q","r+")
    f.write("<?php var_dump(time());?>");
    f.close_write()
    f.each {|line| puts line}
    f.close()
    puts "End PHP Output<br />"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So this is a really strange problem. I have a Java app that acts
Okay, Now admittedly this sounds like a silly question; But, I actually have a
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
I've got (an admittedly strange) try/catch block that checks if a File exists. If
Admittedly, this is something of a first world problem, but I'm sort of picky
This is admittedly a rather loose question. My current understanding of singletons is that
I've got an IQueryable repository (admittedly this is the first time I've tried this)
This is an admittedly silly question, but I honestly don't know if this is
(The title is admittedly not that great. Please forgive my English, this is the
Using Python 2.5 and httplib...... I am admittedly a python novice.....but this seems straight

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.