output_handler problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Diego Vilar

    output_handler problem

    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_gzhandl er"

    won't work:
    php_value output_handler "fwk_output_han dler"

    php.ini:
    will work:
    output_handler "ob_gzhandl er"

    won't work:
    output_handler "fwk_output_han dler"

    I'm checking it through this script:

    <?
    var_dump(ob_lis t_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

    #2
    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_gzhandl er"
    >
    > won't work:
    > php_value output_handler "fwk_output_han dler"
    >
    > php.ini:
    > will work:
    > output_handler "ob_gzhandl er"
    >
    > won't work:
    > output_handler "fwk_output_han dler"
    >
    > I'm checking it through this script:
    >
    > <?
    > var_dump(ob_lis t_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/

    Comment

    • Andy Hassall

      #3
      Re: output_handler problem

      On 20 Apr 2005 06:42:27 -0700, "Diego Vilar" <diegovilar@gma il.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_gzhandl er"[/color]

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

      fwk_output_hand ler 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_gzhandl er"
      >
      > won't work:
      > output_handler "fwk_output_han dler"
      >
      >I'm checking it through this script:
      >
      > <?
      > var_dump(ob_lis t_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_hand ler; 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_hand ler 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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: output_handler problem

        Andy Hassall wrote:[color=blue]
        > On 20 Apr 2005 06:42:27 -0700, "Diego Vilar" <diegovilar@gma il.com>[/color]
        wrote:
        <snip>[color=blue][color=green]
        > > won't work:
        > > php_value output_handler "fwk_output_han dler"[/color]
        >
        > fwk_output_hand ler 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/

        Comment

        • Diego Vilar

          #5
          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!

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            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/

            Comment

            • Diego Vilar

              #7
              Re: output_handler problem

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

              [ ]'s
              Diego

              Comment

              • Andy Hassall

                #8
                Re: output_handler problem

                On 26 Apr 2005 10:13:06 -0700, "R. Rajesh Jeba Anbiah"
                <ng4rrjanbiah@r ediffmail.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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                Comment

                • Diego Vilar

                  #9
                  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_handl er or set_exception_h andler would do for
                  errors and exceptions handlers. That's the point.

                  Comment

                  • Diego Vilar

                    #10
                    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_handl er(), 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_hand ler() function so we could define a user-defined custom
                    DEFAULT handler?

                    Comment

                    Working...