PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.23.2
Last Build: February 25, 2019 14:59pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
file
graph
html
mail
math
misc
mobile
script
string
system
time
psCacheWrite()
Caches data to a file


Description:

These functions are used to cache data to a file
I use this when calling another function takes a long time, and has to parse
a lot of data, that seldom changes

Cache time is on the read function, this allow cache time changes without affecting
files already written.



Usage:


psCacheWrite($mixed,$cFile,[$z])
$mixed = single var, or an array: is $mixed = 1 or $mixed[0] = 1
$cFile = Name of file to save, ex: /tmp/data.cache
$z = compression, 0 to 9


Example:

	$wFile = "test.cache";
$ary = psCacheRead($wFile);

if ($ary == false)
{
print"* Cache Expired\r\n";

$d['gallardo'] = "green";
$d['yellow'] = "yellow";

psCacheWrite($d,$wFile,20);
}




Code:



function psCacheWrite($mixed,$cFile,$z=0)
{
//print"* psCacheWrite()\r\n";
$cache['ts'] = time();
$cache['z'] = $z;
if ($z == 0 )
{
$cache['data'] = $mixed;
}
else
{
$cache['data'] = gzcompress(serialize($mixed), $z);
}
file_put_contents($cFile,serialize($cache));

}

Changlelog:

11/23/2018 - added support for compressed data


See Also

  psCacheRead()
  psCacheWrite()
And a shot out to:

LinuxSimple - www.linuxsimple.com
PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site