Shutdown Functions

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Shutdown Functions
« on May 10th, 2012, 06:30 PM »
I know you guys been remolding SMF so by now you have to be familiar with all the SMF code base.

Is there any registered shutdown functions in SMF? If so where are they located and do they do anything with the output buffer?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Shutdown Functions
« Reply #1, on May 10th, 2012, 06:42 PM »
I don't believe there are any registered shutdown functions, because everything is funnelled manually to redirectexit() and obExit() as desired. obExit does the cleanup and handles certain buffer manipulations in itself, and also calls the buffer hook as necessary.

There is ssi_shutdown but I don't believe it's a registered shutdown function. Of course, just doing a bulk search on the codebase for register_shutdown would tell you for sure ;)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Shutdown Functions
« Reply #2, on May 10th, 2012, 06:58 PM »
It looks like I am going to have to search. It seems the footer of the site is getting called after my shutdown function. I need to register my shutdown function after everything that needs to be outputted has been done. I noticed this because I echoed some content in my shutdown function and it popped up right under the copyright but before the closing html.

I still however looking through the sources can't find it. I haven't used a search tool in a while also, I think I have one on this PC but forgot what it was called. Too many applications, lol.
Re: Shutdown Functions
« Reply #3, on May 10th, 2012, 08:01 PM »
My bad, should of looked at the source instead of the HTML.

My function looks like it is the last thing called.

On a second question I always wondered what would be the proper way to flush the buffer? I have my own method but sometimes it seems like it doesn't work on all host. Then there is allot of people that say one way works and other way doesn't.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Shutdown Functions
« Reply #4, on May 10th, 2012, 08:05 PM »
ob_flush() is the way to call it but depending on configuration it may not matter. If it works, ob_flush() is how to do it. But if it doesn't, there will be no way to do it because of the configuration being based on waiting for PHP to finish before sending anything on.

Partly it's based on whether you're using PHP as a module or not and partly whether gzip is in use or not. But it feels lot like black magic as to whether it'll work or not.

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Shutdown Functions
« Reply #5, on May 10th, 2012, 09:04 PM »
You probably explain a reason why ob_flush quit working on a script I made on my site a while back. Yeah it seems to line up when I enabled gzip compression in php.ini.

Black magic is right though, you would think they would get it work on all configs. :cool:

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Shutdown Functions
« Reply #6, on May 10th, 2012, 09:06 PM »
Well, gzip requires all the content to have been served in order for it to work, so what happens is that Apache waits until end of processing and then gzips all the content, so you can't really fix it.

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Shutdown Functions
« Reply #7, on May 10th, 2012, 11:11 PM »
More troubles, I found out there is no shutdown functions, there is ob_start('ob_sessrewrite'); in Subs.php which is called at the end to rewrite the output buffer. Function ob_sessionwrite is in QueryString.php, however trying to connect to a SQLite DB in the callback function fails, but however trying to connect to a MySql DB in this function succeeds.

This is also where Pretty Urls does the rewrite, so I am trying to get my SQLite cache to store the topic urls but cannot use a SQLite DB in the callback function.

Go figure, you can write to a file or use a MySql DB in the callback function but not a SQLite DB. Is this a PHP bug?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Shutdown Functions
« Reply #8, on May 10th, 2012, 11:16 PM »
How curious. I have no idea why that night be.

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Shutdown Functions
« Reply #9, on May 10th, 2012, 11:23 PM »
What is a real pain it just exits without displaying any errors or anything not even the HTML of the site.

I am going to have to run this small scale to see if it is a problem with SMF or the ob_start callback. If it is in the callback then it has to be a PHP bug, if not then it is a SMF bug.
Re: Shutdown Functions
« Reply #10, on May 10th, 2012, 11:32 PM »
It is a PHP bug, this is the first time I found a PHP bug that wasn't well known or known at all.

Test script, the output is never delivered. If you remove the sqlite db code it is displayed.
Code: [Select]
<?php
ob_start
('callbackfunc');
echo 
'test test test test test test test test test ';
function 
callbackfunc($buffer) {
$DB = new SQLite3('db');
$DB->exec('CREATE TABLE test (one int, two text);');
$DB->exec('INSERT INTO test VALUES (10, \'some text\')');
return $buffer;
}
?>

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

nend

  • When is a theme, no longer what it was when installed?
  • Posts: 165
Re: Shutdown Functions
« Reply #14, on May 12th, 2012, 04:04 AM »
I reported a but to php.net. I am 100% sure my code is not to blame and this is a PHP bug. Something to do with how PHP interacts with SQLite.

What a pain though, I can't continue to develop something that isn't going to be able to work in all scenarios. :heck: