Drupal 6 theme registry got too big for caching

While back I tripped into a problem while developing drupal 6 site. Site got slow and eventually errors started to raise. First php memory limit was exceeded. After I set memory limit bigger new kind of error raised. It was exceeding max_allowed_packet size for mysql. So I raised it with doubt and fear. Since I'am new to drupal I did not think much of it and thought drupal is some kind of beast and needs it for granted.

For a while everything worked (but page was slow) fine, but eventually it raised again while adding new template files to project. Then I really realised that something is very wrong. Finally I got some time to investigate what is wrong and here is what I found. do in hurry

Problem

I was getting an error in every page load, after clearing cache. It goed like this.

Warning: Got a packet bigger than 'max_allowed_packet' bytes query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (1, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:25607278:\"Got a packet bigger than 'max_allowed_packet' bytes\nquery: UPDATE cache SET data = 'a:297:{s:24:\\"block_admin_display_form\\";a:8:{s:8:\\"template\\";s:38:\\"modules/block/block-admin-display-form\\";s:4:\\"file\\";s:15:\\"block.admin.inc\\";s:9:\\"arguments\\";a:1:{s:4:\\"form\\";N;}s:4:\\"type\\";s:6:\\"module\\";s:10:\\"theme path\\";s:13:\\"modules/block\\";s:13:\\"include files\\";a:1:{i:0;s:31 in /var/www/dev/janar/myprojectname/includes/database.mysqli.inc on line 128
As it turned out- problem was that cacheable data was too big for transferring to database in method cache_set. It exceeded max_allowed_packet size and tried to log that error wich also failed because of that. There was too much overhead data for every registered template file arguments in theme_registry:templatename cache array. That's what happens when you go too fast and assume something.

Solution

I was using theme_hook wrong. I was passing predefined input parameters along to the theme arguments, but actually that was not needed. Only keys was need to be set wich will be filled later.

I changed this implemetation

function modulename_theme( $vars ) {
	return array(
		'modulename_templatename' => array(
			'template' => 'modulename-templatename',
			'arguments' => array( 'vars' => $vars ),
		),
	);
}
to this
function modulename_theme( ) {
	return array(
		'modulename_templatename' => array(
			'template' => 'modulename-templatename',
			'arguments' => array( 'vars' => array() ),
		),
	);
}
And that was it. Simple mistake what I was doing was passing input vars along.

Janar Jürisson I am web developer who is interested in creating clean, fast and clutter free pages. Trying to think more "User-centered" because after all they will be using apps that I create. Also fan of shared information, inspiration and alternative thinking because information gives you freedom.