MyBB Community Forums

Full Version: thread views is stuck if php shutdown function not enabled.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone, I was very busy and didn't visit mybb community since long time, so please forgive me if this is a duplicated report or something similar (take any required action).
in showthread.php the update thread views doesn't check if the shutdown function is enabled or not, it just uses it, as a result if this function doesn't work, the thread views do not updated.

to be more specific
the following code from showthread.php
if($mybb->settings['delayedthreadviews'] == 1)
	{
		$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
	}
	else
	{
		$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
	}
	++$thread['views'];

as I see, it should be something like
if($mybb->settings['useshutdownfunc'] ==1)
	{	
		if($mybb->settings['delayedthreadviews'] == 1)
		{
			$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
		}
		else
		{
			$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
		}
	}
	else
	{
	if($mybb->settings['delayedthreadviews'] == 1)
		{
			$db->query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
		}
		else
		{
			$db->query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
		}
	}
	++$thread['views'];
It might be just as fine to change the shutdown_query function to check if the setting is on or not.
I agree with you, but it will require changes on most (if not all) db classes (db_mysql.php, db_mysqli.php, etc..)
so I thought this more flexible solution.
That's actually not the bug. Those queries should be running either way. All the setting does is ask whether we should use the php shutdown functionality, and if not, we run it at the end of the output_page() function. I think there might be a bug in that though.
that's true Ryan, I'll try to take a look at inc/functions.php later tomorrow when I come back from my workplace.
maybe I can help to get the right fix for it.
thank you dear.
Here is my test fix. In inc/class_core.php find and remove:

// Old version of PHP, need to register_shutdown_function
$this->use_shutdown = true;
register_shutdown_function(array(&$this, "__destruct"));

In inc/init.php find:

$mybb->cache = &$cache;

add after:

if($mybb->settings['useshutdownfunc'] != 0)
{
	$mybb->use_shutdown = true;
	register_shutdown_function(array(&$mybb, "__destruct"));
}

Please let me know if this fix works. I'm uncomfortable messing with these files so I would like it if anybody who reads this to try this fix as well and report if it works or not (with the "Use Shutdown Function" setting both off and on).

Thanks,
Ryan
I have sent a Pm for the user who reported this problem (user at my forum) to ask him to give me the permission to test this fix on his forum, once he agrees, I'll test it and replay back with the result.