Page 2 of 2

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

Posted: Wed Jul 23, 2008 8:21 am
by mrmut
Thank everybody, important thing is that we have started.  :D

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

Posted: Fri Jul 25, 2008 4:00 am
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

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

Posted: Fri Jul 25, 2008 11:03 am
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.