Q: Global content block limit? - Centralizing numerical values.

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: Q: Global content block limit? - Centralizing numerical values.

Post by mrmut »

Thank everybody, important thing is that we have started.  :D
viebig

Re: Q: Global content block limit? - Centralizing numerical values.

Post by viebig »

well, I just sent you a new version of the tag, can be used as a UDT with the code.

The biggest problem was the disk access time, plus memory and processor operations, well we have a lot of calls.

My idea was caching the first array in a global variable, and calling it later, need just one fopen.

Maybe you guys can analyse the idea, let me know what do you think. I´m getting 0.4s on a busy server, more that 100 calls to the plugin. I think it´s acceptable! Anyway, you can try the full caching mod after the site is done!

Code: Select all

// Edit this line and point to your URL
	$URL = "http://domain/val.csv";
	
	global $gCms;
	
	// if is not cached
	if (!is_array($gCms->variables['csv']))
	{
		// Dont change anything further
		$handle = fopen($URL,"r");
		$array = array();
		while (($data = fgetcsv($handle, 1000, ",")) !== false)
		{
			$x++;
			if($x == 1)
			{
				$values = $data;
			}
			else 
			{
				foreach ($data as $value)
				{
					if ($c == 0)
					{
						$array[$value] = array();
						$element = $value;
					}
					else
					{
						$array[$element][$values[$c]] = $value;					
					}
					$c++;
				}
				$c=0;
			}
		}
		fclose ($handle);
		// cache into a global variable
		$gCms->variables['csv'] = $array;
		return $array[$params['element']][$params['value']];
	}
	// if is cached
	else
	{
		$array = $gCms->variables['csv'];
		return $array[$params['element']][$params['value']];
	}
Let me know
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: Q: Global content block limit? - Centralizing numerical values.

Post by mrmut »

OK, this is great.

You can check it, it is 0.13 sec now, about 100 fold increase in speed!

http://www.pse.pbf.hr/cms/


This is fantastic!

I will now populate the CSV with full data, and will post findings.
Post Reply

Return to “CMSMS Core”