# Assistance using php_start_ob_buffer

- Thread: https://externals.io/message/38033
- Original archive: https://news-web.php.net/php.internals/38033
- Started by Eric Len on 2008-05-31T16:28:11+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #38033 — Eric Len — 2008-05-31T16:28:11+00:00

URL: https://externals.io/message/38033#38033

Hi,

I'm trying to write an extension that(running under php in fcgi mode) 
does the equivalent of

-php.ini
auto_prepend_file = start.inc
auto_append_file = end.inc

-start.inc
 `ob_start()`

-end.inc
$len = `ob_get_length()`
// modify buffer slightly based on length value
// php prints final buffer on script termination


So I thought I merely needed to do the C equivalent of these, in short:

RINIT

php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC);


RSHUTDOWN

zval * outbuf = NULL;
zval outbuflen;

INIT_ZVAL(outbuflen);

if ( php_ob_get_length(&outbuflen TSRMLS_CC) != FAILURE && 
Z_L_VAL(outbuflen) != 0 ) {

	ALLOC_INIT_ZVAL(outbuf);
	php_ob_get_buffer(outbuf TSRMLS_CC);

	// Modify buffer based on len parameter
}

// Done php prints buffer by itself on script return


However no matter what variation on the above I've tried, including 
different php_ob_* api calls I can't ever get any buffer length(I do see 
script data output). It's like `ob_start()` was never called.

In php.ini I have
output_buffering = Off

Can someone please point out what I'm missing here? thanks!

Dal Eric Len

---

## #38053 — Eric Len — 2008-06-01T15:20:01+00:00

URL: https://externals.io/message/38033#38053 · In reply to: #38033

Okay after looking at the php source looks like the problem is in 
php_request_shutdown where it flushes all the buffers.

So I'm trying from my extension to register a shutdown function to be 
called prior to that(only alternative I see other than mucking the php 
source).

I've figured out basic calling for the

zif_register_shutdown_function

but I'm stuck on how to put something on the

argument_stack

so that it can pass

zend_get_parameters_array

which is called in z

if_register_shutdown_function.

any help appreciated

thanks
Eric


Eric Len wrote:
> Hi,
> 
> I'm trying to write an extension that(running under php in fcgi mode) 
> does the equivalent of
> 
> -php.ini
> auto_prepend_file = start.inc
> auto_append_file = end.inc
> 
> -start.inc
> `ob_start()`
> 
> -end.inc
> $len = `ob_get_length()`
> // modify buffer slightly based on length value
> // php prints final buffer on script termination
> 
> 
> So I thought I merely needed to do the C equivalent of these, in short:
> 
> RINIT
> 
> php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC);
> 
> 
> RSHUTDOWN
> 
> zval * outbuf = NULL;
> zval outbuflen;
> 
> INIT_ZVAL(outbuflen);
> 
> if ( php_ob_get_length(&outbuflen TSRMLS_CC) != FAILURE && 
> Z_L_VAL(outbuflen) != 0 ) {
> 
>     ALLOC_INIT_ZVAL(outbuf);
>     php_ob_get_buffer(outbuf TSRMLS_CC);
> 
>     // Modify buffer based on len parameter
> }
> 
> // Done php prints buffer by itself on script return
> 
> 
> However no matter what variation on the above I've tried, including 
> different php_ob_* api calls I can't ever get any buffer length(I do see 
> script data output). It's like `ob_start()` was never called.
> 
> In php.ini I have
> output_buffering = Off
> 
> Can someone please point out what I'm missing here? thanks!
> 
> Dal Eric Len
