# PHP ob\_start in Ruby

**URL:** <https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853>\
**Category:** Rails\
**Created:** [January 19, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853 "2006-01-19T19:19:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@eduard](https://www.ruby-forum.com/u/eduard)\
**Post date:** [January 19, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853/1 "2006-01-19T19:19:01Z")

</div>

I need to include Content-Length in each file. In PHP it would be:

\<?php ob\_start(); ?\>

html

\<?php header('Content-Length: ' . ob\_get\_length()); ob\_end\_flush(); ?\>

How can I do the same in Ruby?

Thanks,  
eduard

---

<div class="post-metadata">

**Author:** ![eduard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@eduard](https://www.ruby-forum.com/u/eduard)\
**Post date:** [January 19, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853/2 "2006-01-19T19:28:06Z")

</div>

I think there should be a “how to do equivalent PHP function in Ruby”  
page on the Wiki…

eduard wrote:

> ?\>
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

## – I do things for love or money

## +44 (0)7941 219 501

aim:oulalipo | yahoo:tachekent

---

<div class="post-metadata">

**Author:** ![eduard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@eduard](https://www.ruby-forum.com/u/eduard)\
**Post date:** [January 19, 2006, 11:14pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853/3 "2006-01-19T23:14:41Z")

</div>

Dorian M. wrote:

> I think there should be a “how to do equivalent PHP function in Ruby”  
> page on the Wiki…

I’ve started [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/PHPEquivalents).  
The idea is that each page in the PHP manual should have an equivalent  
in the Rails Wiki, and each PHP function should have a page either  
showing the way you do it in Ruby/Rails, or a short explanation as to  
why it’s not necessary. I made a quick start to the main menu and the  
date/time functions to show what could be done… Good idea? Bad? If  
people like it, I’ll try to keep up with filling it, but it’d be good to  
have a few others at it, too.

---

<div class="post-metadata">

**Author:** ![eduard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@eduard](https://www.ruby-forum.com/u/eduard)\
**Post date:** [January 19, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853/4 "2006-01-19T23:20:43Z")

</div>

In your Application Controller, add this:

after\_filter { |controller|  
controller.response.headers[‘Content-Length’] =  
controller.response.body.length

}

* * *

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of eduard  
Sent: Thursday, January 19, 2006 9:40 AM  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] PHP ob\_start in Ruby

I need to include Content-Length in each file. In PHP it would be:

\<?php ob\_start(); ?\>

html

\<?php header('Content-Length: ' . ob\_get\_length()); ob\_end\_flush(); ?\>

How can I do the same in Ruby?

Thanks,  
eduard

---

<div class="post-metadata">

**Author:** ![eduard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3da27b/32.png) [@eduard](https://www.ruby-forum.com/u/eduard)\
**Post date:** [January 20, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/php-ob-start-in-ruby/52853/5 "2006-01-20T21:10:00Z")

</div>

Thanks Tom, it works great!
