Connecting Tech Pros Worldwide Help | Site Map

output_handler problem

Diego Vilar
Guest
 
Posts: n/a
#1: Jul 17 '05
When I set output_handler (either through php.ini our .htaccess) it
does not work with my custom funcions. Why is that?

..htaccess:
will work:
php_value output_handler "ob_gzhandler"

won't work:
php_value output_handler "fwk_output_handler"

php.ini:
will work:
output_handler "ob_gzhandler"

won't work:
output_handler "fwk_output_handler"

I'm checking it through this script:

<?
var_dump(ob_list_handlers());
?>

and all I get is "array(0) { }" when trying to set the handler to any
function other than ob_gzhandler.

Any ideas?

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#2: Jul 17 '05

re: output_handler problem


Diego Vilar wrote:[color=blue]
> When I set output_handler (either through php.ini our .htaccess) it
> does not work with my custom funcions. Why is that?
>
> .htaccess:
> will work:
> php_value output_handler "ob_gzhandler"
>
> won't work:
> php_value output_handler "fwk_output_handler"
>
> php.ini:
> will work:
> output_handler "ob_gzhandler"
>
> won't work:
> output_handler "fwk_output_handler"
>
> I'm checking it through this script:
>
> <?
> var_dump(ob_list_handlers());
> ?>
>
> and all I get is "array(0) { }" when trying to set the handler to any
> function other than ob_gzhandler.[/color]

Yes, this definitely looks like a bug.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: output_handler problem


On 20 Apr 2005 06:42:27 -0700, "Diego Vilar" <diegovilar@gmail.com> wrote:
[color=blue]
>When I set output_handler (either through php.ini our .htaccess) it
>does not work with my custom funcions. Why is that?[/color]

Because they haven't been defined yet.
[color=blue]
>.htaccess:
> will work:
> php_value output_handler "ob_gzhandler"[/color]

ob_gzhandler is a PHP function. So it's already defined.
[color=blue]
> won't work:
> php_value output_handler "fwk_output_handler"[/color]

fwk_output_handler is your custom function. Where is it defined? In a PHP
file? But PHP hasn't started reading any files yet, it's still parsing
configuration.
[color=blue]
>php.ini:
> will work:
> output_handler "ob_gzhandler"
>
> won't work:
> output_handler "fwk_output_handler"
>
>I'm checking it through this script:
>
> <?
> var_dump(ob_list_handlers());
> ?>
>
>and all I get is "array(0) { }" when trying to set the handler to any
>function other than ob_gzhandler.
>
>Any ideas?[/color]

(a) Use ob_start in whatever include file contains fwk_output_handler; the
function will then be defined since it's parsed the include file, so you can
use it as an output handler.

(b) Define fwk_output_handler in a PHP extension - this is likely to be more
pain than it's worth.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#4: Jul 17 '05

re: output_handler problem


Andy Hassall wrote:[color=blue]
> On 20 Apr 2005 06:42:27 -0700, "Diego Vilar" <diegovilar@gmail.com>[/color]
wrote:
<snip>[color=blue][color=green]
> > won't work:
> > php_value output_handler "fwk_output_handler"[/color]
>
> fwk_output_handler is your custom function. Where is it defined? In[/color]
a PHP[color=blue]
> file? But PHP hasn't started reading any files yet, it's still[/color]
parsing[color=blue]
> configuration.[/color]

The function has to be present in function table is a valid point.
But, the manual has no hint about that. Also, I think, if it works for
ob_start(), it should also work for setting handler in ini. At least
for me, there is much differences.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Diego Vilar
Guest
 
Posts: n/a
#5: Jul 17 '05

re: output_handler problem


Yep... The behavior makes sense once the function is not defined yet,
but the output_handler directive should at least be changable through
user scripts so one could set a custom default output_handler without
having to build an extension.

Anyway, thank you guys!

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#6: Jul 17 '05

re: output_handler problem


Diego Vilar wrote:[color=blue]
> Yep... The behavior makes sense once the function is not defined yet,
> but the output_handler directive should at least be changable through
> user scripts so one could set a custom default output_handler without
> having to build an extension.[/color]

Have you reported this behaviour to PHP developers? If not, I'd like
to do it.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Diego Vilar
Guest
 
Posts: n/a
#7: Jul 17 '05

re: output_handler problem


No, I haven't reported it. Go ahead and report it if you will.

[ ]'s
Diego

Andy Hassall
Guest
 
Posts: n/a
#8: Jul 17 '05

re: output_handler problem


On 26 Apr 2005 10:13:06 -0700, "R. Rajesh Jeba Anbiah"
<ng4rrjanbiah@rediffmail.com> wrote:
[color=blue]
>Diego Vilar wrote:[color=green]
>> Yep... The behavior makes sense once the function is not defined yet,
>> but the output_handler directive should at least be changable through
>> user scripts so one could set a custom default output_handler without
>> having to build an extension.[/color]
>
> Have you reported this behaviour to PHP developers? If not, I'd like
>to do it.[/color]

You can change the output handler in a user script - you call ob_start()
specifying a callback. Not sure what there is to report...

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Diego Vilar
Guest
 
Posts: n/a
#9: Jul 17 '05

re: output_handler problem


Yes, we can change the output handler in a user script using
ob_start(), but we cannot define a new default output_handler in a user
script, just as set_error_handler or set_exception_handler would do for
errors and exceptions handlers. That's the point.

Diego Vilar
Guest
 
Posts: n/a
#10: Jul 17 '05

re: output_handler problem


Again, just to make it clear so we do not lose the focus here, the
thread is about setting a user-defined function as the DEFAULT handler.

The manual states the following about the directive output_handler:
"You can redirect all of the output of your scripts to a function. For
example, if you set output_handler to mb_output_handler(), character
encoding will be transparently converted to the specified encoding.
Setting any output handler automatically turns on output buffering."

output_handler is a PHP_INI_PERDIR changeable directive. That alone
makes it clear that the function to be used as the default output
handler should be available at the time php.ini and .htaccess are read,
which leads us to the need to either use an already provided function,
or code our own in an extension. But wouldn't that be nice to have a
set_output_handler() function so we could define a user-defined custom
DEFAULT handler?

Closed Thread