: : ?

     SQL
 SQL
...

,
<?
$sql="select * from tb_news order by id desc limit 1";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);

echo $row["data"];
echo $row["newstext"];
?>

, MySQL, .

( ):
<?
$sql="select * from tb_news order by id desc limit 1";
$res=new MySQLCache($sql, 300); // 300
$row=$res->fetch_assoc();

echo $row["data"];
echo $row["newstext"];
?>

, - .

( ):

$res=mysql_query($sql);
$row=mysql_fetch_array($res);

:
$res=new MySQLCache($sql, 300); // 300
$row=$res->fetch_assoc();

.

. , header.php:
include("cache_sql.php");

.

:
<?php
class MySQLCache{
var $CachePath = 'cache_data/'; //
var $PeakFilename = 'speed_site.log'; // ( )
var $Debug = true;
var $FromCache = false;
var $DataDate = 0;
var $errno = 0;
var $error = '';
var $Peak = array
(
0,
'',
'',
'',
);
var $NextRowNo = 0;
var $ResultData = array
(
'fields' => array(),
'data' => array(),
);
function MySQLCache($query, $valid = 10)
{
if ($this->CachePath == '')
{
$this->CachePath = dirname(__FILE__);
}
$query = trim($query);

//if (!eregi('^SELECT', $query))
//{
//return mysql_query($query);
//}

$filename = $this->CachePath . '/' . md5($query) . '.txt';
if ((@$file = fopen($filename, 'r')) && filemtime($filename) > (time() - $valid))
{
flock($file, LOCK_SH);
$serial = file_get_contents($filename);
$this->ResultData = unserialize($serial);
$this->DataDate = filemtime($filename);
$this->FromCache = true;
fclose($file);
return true;
}
if ($file)
{
fclose($file);
}
$time_start = microtime(true);
@ $SQLResult = mysql_query($query);
$time_end = microtime(true);
$this->DataDate = time();
$time_exec = $time_end - $time_start;
if (!$SQLResult)
{
if ($this->Debug)
{
die('Error from query "' . $query . '": ' . mysql_error());
}
else
{
$this->errno = mysql_errno();
$this->error = mysql_error();
return false;
}
}
$peak_filename = $this->CachePath . '/' . $this->PeakFilename;
if (@$file = fopen($peak_filename, 'r'))
{
flock($file, LOCK_SH);
$fdata = file($peak_filename);
foreach ($fdata as $key => $value)
{
$this->Peak[$key] = trim($value);
}
$this->Peak[0] = floatval($this->Peak[0]);
}
if ($file)
{
fclose($file);
}
if ($time_exec > $this->Peak[0])
{
$this->Peak = array
(
$time_exec,
date('r'),
$query,
$_SERVER['SCRIPT_FILENAME'],
);
$file = fopen($peak_filename, 'w');
flock($file, LOCK_EX);
fwrite($file, implode("n", $this->Peak));
fclose($file);
}
$nf = mysql_num_fields($SQLResult);
for ($i = 0; $i < $nf; $i++)
{
$this->ResultData['fields'][$i] = mysql_fetch_field($SQLResult, $i);
}
$nr = mysql_num_rows($SQLResult);
for ($i = 0; $i < $nr; $i++)
{
$this->ResultData['data'][$i] = mysql_fetch_row($SQLResult);
}
$file = fopen($filename, 'w');
flock($file, LOCK_EX);
fwrite($file, serialize($this->ResultData));
fclose($file);
return true;
}
function num_fields()
{
return sizeof($this->ResultData['fields']);
}
function field_name($num)
{
if (isset($this->ResultData['fields'][$num]))
{
return $this->ResultData['fields'][$num]->name;
}
else
{
return false;
}
}
function fetch_field($num)
{
if (isset($this->ResultData['fields'][$num]))
{
return $this->ResultData['fields'][$num];
}
else
{
return false;
}
}
function field_len($num)
{
if (isset($this->ResultData['fields'][$num]))
{
return $this->ResultData['fields'][$num]->max_length;
}
else
{
return false;
}
}
function field_type($num)
{
if (isset($this->ResultData['fields'][$num]))
{
return $this->ResultData['fields'][$num]->type;
}
else
{
return false;
}
}
function field_flags($num)
{
if (!isset($this->ResultData['fields'][$num]))
{
return false;
}
$result = array();
if ($this->ResultData['fields'][$num]->not_null)
{
$result[] = 'not_null';
}
if ($this->ResultData['fields'][$num]->primary_key)
{
$result[] = 'primary_key';
}
if ($this->ResultData['fields'][$num]->unique_key)
{
$result[] = 'unique_key';
}
if ($this->ResultData['fields'][$num]->multiple_key)
{
$result[] = 'multiple_key';
}
if ($this->ResultData['fields'][$num]->blob)
{
$result[] = 'blob';
}
if ($this->ResultData['fields'][$num]->unsigned)
{
$result[] = 'unsigned';
}
if ($this->ResultData['fields'][$num]->zerofill)
{
$result[] = 'zerofill';
}
if ($this->ResultData['fields'][$num]->binary)
{
$result[] = 'binary';
}
if ($this->ResultData['fields'][$num]->enum)
{
$result[] = 'enum';
}
if ($this->ResultData['fields'][$num]->auto_increment)
{
$result[] = 'auto_increment';
}
if ($this->ResultData['fields'][$num]->timestamp)
{
$result[] = 'timestamp';
}
return implode(' ', $result);
}
function num_rows()
{
return sizeof($this->ResultData['data']);
}
function fetch_row()
{
if (($this->NextRowNo+1) > $this->num_rows())
{
return false;
}
$this->NextRowNo++;
return $this->ResultData['data'][$this->NextRowNo - 1];
}
function fetch_assoc()
{
if (($this->NextRowNo + 1) > $this->num_rows())
{
return false;
}
for ($i = 0; $i < $this->num_fields(); $i++)
{
$result[$this->ResultData['fields'][$i]->name] =
$this->ResultData['data'][$this->NextRowNo][$i];
}
$this->NextRowNo++;
return $result;
}
}
?>

cache_data CMOD 777 .

... ...


: »   |   : kirill   |   : 4954
: 217
: 14
ICQ: 207679
- 318 +
  : vlaf   |   :   |   : 29 2011  
?
: 738
: 50
ICQ: --
- 4 +
  : Green-wm   |   :   |   : 29 2011  
: VLAF
?

- .
: 217
: 14
ICQ: 207679
- 318 +
  : vlaf   |   :   |   : 29 2011  
winked . )
: 167
: 16
ICQ: 553069709
- 239 +
  : ZKolyaNZ   |   :   |   : 29 2011  
MySQL , ))
, .
sooofast 8-15 SQL 10 , , - iphoster 1000 , .
: 64
: 8
ICQ: 959098
- 82 +
  : kirill   |   :   |   : 29 2011  
: ZKolyaNZ
MySQL , )) , . sooofast 8-15 SQL 10 , , - iphoster 1000 , .


))
100 )))) )))
!!))

: 167
: 16
ICQ: 553069709
- 239 +
  : ZKolyaNZ   |   :   |   : 29 2011  
kirill,

)
php )
: 64
: 8
ICQ: 959098
- 82 +
  : kirill   |   :   |   : 29 2011  
CMS )) )))

DLE ))
: 240
: 6
ICQ: 573235722
- -896 +
  : VELIK505   |   :   |   : 29 2011  
memcached ?
: 129
: 9
ICQ: 646895
- 178 +
  : SpawN   |   :   |   : 29 2011  
no
: 64
: 8
ICQ: 959098
- 82 +
  : kirill   |   :   |   : 29 2011  
: VELIK505
memcached ?




: SpawN


)
)))
: 240
: 6
ICQ: 573235722
- -896 +
  : VELIK505   |   :   |   : 29 2011  
. 15
: 121
: 2
ICQ: 819374
- 118 +
  : Rufus   |   :   |   : 29 2011  
, - SQL ... .
: 240
: 6
ICQ: 573235722
- -896 +
  : VELIK505   |   :   |   : 29 2011  
: 76
: 18
ICQ: 634377420
- 149 +
  : BeerMan   |   :   |   : 30 2011  
???
: 240
: 6
ICQ: 573235722
- -896 +
  : VELIK505   |   :   |   : 30 2011  
. . . xcache
: 76
: 18
ICQ: 634377420
- 149 +
  : BeerMan   |   :   |   : 30 2011  
??
@ob_start("ob_gzhandler");
@ob_end_flush();
: 240
: 6
ICQ: 573235722
- -896 +
  : VELIK505   |   :   |   : 31 2011  
.

.
: 13
: 2
ICQ: 521839
- 14 +
  : master   |   :   |   : 31 2011  
.
: 64
: 8
ICQ: 959098
- 82 +
  : kirill   |   :   |   : 31 2011  
: master
.

)
: 95
: 2
ICQ: 656527
- 355 +
  : NGS   |   : NGS Engine   |   : 07 2011  
$res=new MySQLCache($sql, 300); // 300
$row=$res->fetch_assoc();...

???
?

,

, , - !
: 64
: 8
ICQ: 959098
- 82 +
  : kirill   |   :   |   : 07 2011  
: NGS
, , - !

=))) )))
: 77
: 2
ICQ: 50406060
- 191 +
  : Contego   |   :   |   : 04 2011  
.
: 0.007 , : 0.218254 , 0.041976 , 0.018141 , 0.009636 , 0.012751
+ .

.. .. :(
: 63
: 10
ICQ: --
- 3 +
  : Hitman   |   :   |   : 27 2012  
.


, , .