I've done some minor hacks on zp to boost performance. I'm using eAccelerator with PHP-FastCGI, but these hacks can easily be ported to APC, XCache or even memcached. Alternatively, you may also use disk-based caching.
[b]#1 Reduce load on the DB server:[/b]
This is based on the caching technique described on http://www.zenphoto.org/2008/01/hacks/ We'll use eAccelerator shm cache instead of storing the query results on disk.
function query_single_row($sql, $noerrmsg=false) {
if ($cache = get_cache($sql))
return $cache;
$result = query($sql, $noerrmsg);
if ($result) {
$data = mysql_fetch_assoc($result);
store_cache($sql, $data);
return $data;
}
else {
return false;
}
}
`
function query_full_array($sql, $noerrmsg = false) {
if ($cache = get_cache($sql))
return $cache;
$result = query($sql, $noerrmsg);
if ($result) {
$allrows = array();
while ($row = mysql_fetch_assoc($result))
$allrows[] = $row;
store_cache($sql, $allrows);
return $allrows;
}
else {
return false;
}
}
`
function store_cache($query, $result_cache) {
$cache_time_out = 600;
if (preg_match("/^(insert|delete|update|replace)\s+/i",$query))
return;
if (stristr($query, "ORDER BY RAND"))
return;
$key = 'sql_' . md5($query);
$val = serialize($result_cache);
eaccelerator_put($key, $val, $cache_time_out);
}
function get_cache($query) {
if (preg_match("/^(insert|delete|update|replace)\s+/i",$query))
return;
if (stristr($query, "ORDER BY RAND"))
return;
$key = 'sql_' . md5($query);
$val = eaccelerator_get($key);
if ( $val != NULL )
return unserialize($val);
}
`
Oops! Posted in the wrong forum.
@admin: Please relocate this thread to the Gen. discussions.