is there a hook firing right after the </html>?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

is there a hook firing right after the </html>?

Haluk Karamete
I need to run ob_get_clean() as soon as the get_footer() is done running -
meaning as soon as the </html> is outputted.

What hook can I use for that?

more insight on why do I need that?
the goal is to put the generated html ( from <doctype to </html> ) into a
transient.
and for this goal, I set the "ob_buffer" using the get_header() action hook.
but that's only half of the deal...
I still need to catch the buffer when i am done with the full page -
meaning when I am done wirth outputting the </html>

is there a hook such as "after_get_footer" ?
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Nashwan Doaqan
There is no 'after_get_footer' hook. Maybe you can use
'template_include' filter to encapsulate the working template with your
ob_* functions. You should notice, some themes doesn't use get_footer
function.. they must include wp_head() but get_footer() isn't required
as far as I know.. Another option may be using
register_shutdown_function() ? ..

Good Luck !

On 2/2/2015 8:09 AM, Haluk Karamete wrote:

> I need to run ob_get_clean() as soon as the get_footer() is done running -
> meaning as soon as the </html> is outputted.
>
> What hook can I use for that?
>
> more insight on why do I need that?
> the goal is to put the generated html ( from <doctype to </html> ) into a
> transient.
> and for this goal, I set the "ob_buffer" using the get_header() action hook.
> but that's only half of the deal...
> I still need to catch the buffer when i am done with the full page -
> meaning when I am done wirth outputting the </html>
>
> is there a hook such as "after_get_footer" ?
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

John Blackbourn
You should take a look at some of the full-page caching plugins which
are available (seeing as that's what you're trying to do) and see how
they operate. The 'shutdown' hook is probably what you're after.

On 2 February 2015 at 06:26, Nashwan Doaqan <[hidden email]> wrote:

> There is no 'after_get_footer' hook. Maybe you can use 'template_include'
> filter to encapsulate the working template with your ob_* functions. You
> should notice, some themes doesn't use get_footer function.. they must
> include wp_head() but get_footer() isn't required as far as I know.. Another
> option may be using register_shutdown_function() ? ..
>
> Good Luck !
>
>
> On 2/2/2015 8:09 AM, Haluk Karamete wrote:
>>
>> I need to run ob_get_clean() as soon as the get_footer() is done running -
>> meaning as soon as the </html> is outputted.
>>
>> What hook can I use for that?
>>
>> more insight on why do I need that?
>> the goal is to put the generated html ( from <doctype to </html> ) into a
>> transient.
>> and for this goal, I set the "ob_buffer" using the get_header() action
>> hook.
>> but that's only half of the deal...
>> I still need to catch the buffer when i am done with the full page -
>> meaning when I am done wirth outputting the </html>
>>
>> is there a hook such as "after_get_footer" ?
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Andrew Nacin-2
In reply to this post by Haluk Karamete
Output buffer callbacks are automatically called at the conclusion of the
script.

There is a 'shutdown' hook that fires on a shutdown handler that you can
also use.

On Mon, Feb 2, 2015 at 12:09 AM, Haluk Karamete <[hidden email]>
wrote:

> I need to run ob_get_clean() as soon as the get_footer() is done running -
> meaning as soon as the </html> is outputted.
>
> What hook can I use for that?
>
> more insight on why do I need that?
> the goal is to put the generated html ( from <doctype to </html> ) into a
> transient.
> and for this goal, I set the "ob_buffer" using the get_header() action
> hook.
> but that's only half of the deal...
> I still need to catch the buffer when i am done with the full page -
> meaning when I am done wirth outputting the </html>
>
> is there a hook such as "after_get_footer" ?
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Haluk Karamete
>
> Output buffer callbacks are automatically called at the conclusion of the
> script.
>


Automatically called bhy WordPress? I'm interested in seeing where that
happens Nacin. I'm not sure what happens in that section of the code...

For my sake, I think I can pretty much rely on shutdown hook. To me, that
fires as much as get_footer hook would fire.
Since my old implementation was running right after the get_footer() call,
and I was fine with that, I should be fine with the shutdown as well.

Looks like 'shutdown' is the only hook left - after the final breath is
given with the </html>.



Interesting...  so to tap into that area, what do you do? modify the core?
But for a generic solution, I want my plug in cache the page at the end. In
this case,  'shutdown' is the only option to



On Mon, Feb 2, 2015 at 12:50 PM, Andrew Nacin <[hidden email]> wrote:

> Output buffer callbacks are automatically called at the conclusion of the
> script.
>
> There is a 'shutdown' hook that fires on a shutdown handler that you can
> also use.
>
> On Mon, Feb 2, 2015 at 12:09 AM, Haluk Karamete <[hidden email]>
> wrote:
>
> > I need to run ob_get_clean() as soon as the get_footer() is done running
> -
> > meaning as soon as the </html> is outputted.
> >
> > What hook can I use for that?
> >
> > more insight on why do I need that?
> > the goal is to put the generated html ( from <doctype to </html> ) into a
> > transient.
> > and for this goal, I set the "ob_buffer" using the get_header() action
> > hook.
> > but that's only half of the deal...
> > I still need to catch the buffer when i am done with the full page -
> > meaning when I am done wirth outputting the </html>
> >
> > is there a hook such as "after_get_footer" ?
> > _______________________________________________
> > wp-hackers mailing list
> > [hidden email]
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Kuba Niewiarowski
In reply to this post by Haluk Karamete
2015-02-02 6:09 GMT+01:00 Haluk Karamete <[hidden email]>:

> the goal is to put the generated html ( from <doctype to </html> ) into a
> transient.
>

This is not a good idea because of wp_options table in database, I think.
There are full page cache plugins which are doin a job.


--
Pozdrawiam, Kuba
Niewiarowski.IT
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Otto-19
In reply to this post by Haluk Karamete
On Mon, Feb 2, 2015 at 3:21 PM, Haluk Karamete <[hidden email]>
wrote:

> > Output buffer callbacks are automatically called at the conclusion of the
> > script.
>
> Automatically called bhy WordPress?



No, by PHP itself, actually.

When you create an output buffer using ob_start() and fail to clear it with
an appropriate ob_end_* call, then PHP will flush the output buffer at the
end of script execution.

Notably, this actually happens before any callbacks that were passed to
register_shutdown_function() are called. Shutdown functions don't get the
contents of the output buffer.

-Otto
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Haluk Karamete
Otto,

Are you saying that by the time ( shutdown_action_hook ) runs, PHP has
already cleared the output_buffer automatically? or am I misunderstanding
you?
I though PHP's internal shutdown functions would run only and only after
the last line of script has been executed...  Since wordpress is still
running at that time, why would PHP clear the output buffer?

In that case, I won't be able to use the 'shutdown' hook for my purpose.



https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L601

601
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L601>
/**602
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L602>
*
Runs just before PHP shuts down execution.603
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L603>
 *604
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L604>
*
@since 1.2.0605
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L605>
*
@access private606
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L606>
 */607
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L607>
function shutdown_action_hook() {608
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L608>
      /**609
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L609>
       * Fires just before PHP shuts down execution.610
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L610>
       *611
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L611>
       * @since 1.2.0612
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L612>
       */613
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L613>
      do_action( 'shutdown' );614
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L614>
615
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L615>
      wp_cache_close();616
<https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L616>
}
That means,

On Mon, Feb 2, 2015 at 1:34 PM, Otto <[hidden email]> wrote:

> On Mon, Feb 2, 2015 at 3:21 PM, Haluk Karamete <[hidden email]>
> wrote:
>
> > > Output buffer callbacks are automatically called at the conclusion of
> the
> > > script.
> >
> > Automatically called bhy WordPress?
>
>
>
> No, by PHP itself, actually.
>
> When you create an output buffer using ob_start() and fail to clear it with
> an appropriate ob_end_* call, then PHP will flush the output buffer at the
> end of script execution.
>
> Notably, this actually happens before any callbacks that were passed to
> register_shutdown_function() are called. Shutdown functions don't get the
> contents of the output buffer.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Nikola Nikolov
Quote from http://php.net/manual/en/function.register-shutdown-function.php
:

"The shutdown callbacks are executed as the part of the request, so it's
possible to send output from them and access output buffers."

Nikola

On Tue, Feb 3, 2015 at 1:00 AM, Haluk Karamete <[hidden email]>
wrote:

> Otto,
>
> Are you saying that by the time ( shutdown_action_hook ) runs, PHP has
> already cleared the output_buffer automatically? or am I misunderstanding
> you?
> I though PHP's internal shutdown functions would run only and only after
> the last line of script has been executed...  Since wordpress is still
> running at that time, why would PHP clear the output buffer?
>
> In that case, I won't be able to use the 'shutdown' hook for my purpose.
>
>
>
>
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L601
>
> 601
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L601
> >
> /**602
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L602
> >
> *
> Runs just before PHP shuts down execution.603
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L603
> >
>  *604
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L604
> >
> *
> @since 1.2.0605
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L605
> >
> *
> @access private606
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L606
> >
>  */607
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L607
> >
> function shutdown_action_hook() {608
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L608
> >
>       /**609
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L609
> >
>        * Fires just before PHP shuts down execution.610
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L610
> >
>        *611
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L611
> >
>        * @since 1.2.0612
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L612
> >
>        */613
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L613
> >
>       do_action( 'shutdown' );614
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L614
> >
> 615
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L615
> >
>       wp_cache_close();616
> <
> https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/load.php#L616
> >
> }
> That means,
>
> On Mon, Feb 2, 2015 at 1:34 PM, Otto <[hidden email]> wrote:
>
> > On Mon, Feb 2, 2015 at 3:21 PM, Haluk Karamete <[hidden email]>
> > wrote:
> >
> > > > Output buffer callbacks are automatically called at the conclusion of
> > the
> > > > script.
> > >
> > > Automatically called bhy WordPress?
> >
> >
> >
> > No, by PHP itself, actually.
> >
> > When you create an output buffer using ob_start() and fail to clear it
> with
> > an appropriate ob_end_* call, then PHP will flush the output buffer at
> the
> > end of script execution.
> >
> > Notably, this actually happens before any callbacks that were passed to
> > register_shutdown_function() are called. Shutdown functions don't get the
> > contents of the output buffer.
> >
> > -Otto
> > _______________________________________________
> > wp-hackers mailing list
> > [hidden email]
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Otto-19
On Mon, Feb 2, 2015 at 5:02 PM, Nikola Nikolov <[hidden email]>
wrote:

> Quote from
> http://php.net/manual/en/function.register-shutdown-function.php
> :
>
> "The shutdown callbacks are executed as the part of the request, so it's
> possible to send output from them and access output buffers."
>
> Nikola
>
>

Yes, my knowledge might be out of date on that one. From lower in the page
it seems that that behavior may have changed between PHP 5.0 and 5.1. In
which case output buffers would be accessible from shutdown callbacks.

-Otto
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

Nikola Nikolov
Yeah, sorry for not providing further info(it's late here too :)), I only
did a quick search.

On Tue, Feb 3, 2015 at 1:26 AM, Otto <[hidden email]> wrote:

> On Mon, Feb 2, 2015 at 5:02 PM, Nikola Nikolov <[hidden email]>
> wrote:
>
> > Quote from
> > http://php.net/manual/en/function.register-shutdown-function.php
> > :
> >
> > "The shutdown callbacks are executed as the part of the request, so it's
> > possible to send output from them and access output buffers."
> >
> > Nikola
> >
> >
>
> Yes, my knowledge might be out of date on that one. From lower in the page
> it seems that that behavior may have changed between PHP 5.0 and 5.1. In
> which case output buffers would be accessible from shutdown callbacks.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: is there a hook firing right after the </html>?

golddty
This post has NOT been accepted by the mailing list yet.
In reply to this post by Haluk Karamete

It sounds really good, too wonderful!