PHP Classes

buffering issue

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  buffering issue  >  (Un) Subscribe thread alerts  
Subject:buffering issue
Summary:multiple buffering levels
Messages:4
Author:Matías montes
Date:2006-11-09 03:29:00
Update:2006-11-09 19:01:02
 

  1. buffering issue   Reply   Report abuse  
Picture of Matías montes Matías montes - 2006-11-09 03:29:00
just reporting an unexpected behaviour when using multiple levels of buffering

I'm currently working with a framework called codeigniter which by default buffers all output sent to the client.
The thing is that when I call StartLayoutCapture() it works on a 2nd. level of buffering which normally shouldn't be a problem, and in fact, it works perfectly well on my testing server.... but when I uploaded the site to the hosting server it breaks when I add an input part.
Looking through the code, it seems the problem is that AddDataPart is cleaning the whole buffer (every level) but only retrieves one level.

It's a bit confusing, but the thing is that under certain circumstances, the layout capture feature doesn't work.

My testing server is an apache 1.3.3 PHP5.0 running under windows

The hosting server has a similar configuration but is running a PHP4.4.3 version under linux

I don't know the reason for this issue, but it made it imposible for me to use the LayoutCapture feature on this particular site :(

  2. Re: buffering issue   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-11-09 05:34:59 - In reply to message 1 from Matías montes
Well, AddDataPart uses ob_end_clean() function which only cleans the topmost buffer level, and not every buffer level as you said.

Anyway, now that you mentioned it I wrote a simple script to test whether it works as expected. I tried it under PHP 4.4 and 5.1 and it works fine.

The code follows below so you can try and check it against the generated output.

I suspect that you may be running an optimizer extension that messes the order of execution of PHP code. This is not uncommon. I do not trust PHP optimizers (any of them). I use a caching extension with optimizer support disabled to play safe.

<?php

require("forms.php");

ob_start();
echo "\t", __LINE__;

ob_start();
echo "\t", __LINE__," form start\n|||";

$form=new form_class;
$form->AddInput(array(
"ID"=>"text",
"NAME"=>"text",
"TYPE"=>"text"
));

$form->StartLayoutCapture();
echo "Before |||";
$form->AddDataPart("Before |||");
$form->AddInputPart("text");
$form->AddDataPart("||| After");
echo "||| After";
$form->EndLayoutCapture();
$form->DisplayOutput();


echo "|||\nform end";
$inner=ob_get_contents();
ob_end_clean();

echo "\n\t", __LINE__;
$outer=ob_get_contents();
ob_end_clean();

echo "Inner: ", serialize($inner), "\n", "Outer: ", serialize($outer), "\n";

?>

Output:

Inner: s:149:" 9 form start
|||<form method="post" action="">
Before |||Before |||<input type="text" name="text" id="text" />||| After||| After</form>
|||
form end";
Outer: s:6:" 6
32";

  3. Re: buffering issue   Reply   Report abuse  
Picture of Matías montes Matías montes - 2006-11-09 18:06:43 - In reply to message 2 from Manuel Lemos
You're probably right about the optimizer, and I didn't think of that one.
Unfortunately I have no control over the hosting server configuration so I'll have to live without the layout capture feature for now.

I'll do further tests with the script you provided and see if I can reach the source of the problem

thanks

  4. Re: buffering issue   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-11-09 19:01:02 - In reply to message 3 from Matías montes
If that is your problem, the optimizer may be affecting many other pieces of code. As a matter of fact, the problem you may be seeing may be affecting the other framework you are using and not necessarily the forms class.

Anyway, it would be useful if you could run the test script that I sent before to see if it outputs the right results.