Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: klopot ze skryptem
Forum PHP.pl > Forum > Przedszkole
acztery
witam mam maly klopot na serwerze home.pl dziala idealnie na lokalnym te¿ ale na ovh.net juz nie moze ktos widzi jakis blad...


Warning: fread(): Length parameter must be greater than 0. in /home/netcom/public_html/hotscripts/includes/getvars.php on line 161

  1. <?php
  2.  
  3. function _self_cacher_getmicrotime(){
  4.  list($usec, $sec) = explode(" ",microtime());
  5.  return ((float)$usec + (float)$sec);
  6. }
  7. class TSelfCacher{
  8. var $_log_performance=true;
  9. var $_log_full_filename;
  10. var $_start_time;
  11. //
  12. var $_cache_to_dir="cache/";  //linux
  13. var $_cached_filename;
  14. var $_cached_full_filename;
  15. var $_cached_content;
  16. //
  17. //constructor
  18. function TSelfCacher($ALogPerformance=FALSE){
  19.  //if $ALogPerformance ,enable performance log
  20.  $this->_log_performance=$ALogPerformance?TRUE:FALSE;
  21.  if($this->_log_performance) $this->_start_time=_self_cacher_getmicrotime();
  22.  global $HTTP_SERVER_VARS;
  23.  if($HTTP_SERVER_VARS["REQUEST_METHOD"]=="POST") return; //don't cache posted file
  24.  $this->setCacheFileAndDir();
  25.  $this->existOrMakeToDir();
  26.  if($this->getCachedContent()){
  27. $this->show();
  28.  }else{
  29. $this->startCache();
  30. return $this;
  31.  }
  32. }
  33. function setCacheFileAndDir(){
  34.  global $HTTP_SERVER_VARS;
  35.  $this->_cached_filename=md5($HTTP_SERVER_VARS["REQUEST_URI"]).'_'.date("G").".cache";
  36.  $this->_cache_to_dir.="/".date("Ymd"); //
  37.  $this->_cached_full_filename=$this->_cache_to_dir."/".$this->_cached_filename;
  38.  if($this->_log_performance){$this->_log_full_filename=$this->_cache_to_dir."/performance.log";}
  39. }
  40. function getCachedContent(){ //return true when get cached content before ,or return false
  41.  if(!file_exists($this->_cached_full_filename)){ return FALSE;}
  42.  if($fp=@fopen($this->_cached_full_filename,"r")){
  43.  flock($fp,LOCK_SH);
  44.  $this->_cached_content=fread($fp,filesize($this->_cached_full_filename));
  45.  flock($fp,LOCK_UN);
  46.  fclose($fp);
  47.  return TRUE;
  48.  }else{
  49.  return FALSE;
  50.  }
  51. }
  52. function setCachedContent(&$AContent){  //call function by ref can speed up
  53.  $this->_cached_content=$AContent;
  54. }
  55. function writeCachedContent(){
  56.  if($fp=@fopen($this->_cached_full_filename,"w")){
  57.  flock($fp,LOCK_EX);
  58.  fwrite($fp,$this->_cached_content);
  59.  flock($fp,LOCK_UN);
  60.  fclose($fp);
  61.  if($this->_log_performance){
  62. $this->logToFile();
  63.  }
  64.  return TRUE;
  65.  }else{
  66.  return FALSE;
  67.  }
  68. }
  69. function logToFile(){
  70.  $_spent_time=_self_cacher_getmicrotime()-$this->_start_time;
  71.  if($fp=@fopen($this->_log_full_filename,"a")){
  72.  flock($fp,LOCK_EX);
  73.  fputs($fp,date("[Y-m-d H:i:s]").$this->_cached_full_filename." ".$_spent_time." microsecondsn");
  74.  flock($fp,LOCK_UN);
  75.  fclose($fp);
  76.  return TRUE;
  77.  }else{
  78.  return FALSE;
  79.  }
  80. }
  81. function startCache(){
  82.  ob_start("_cacher_call_back");
  83. }
  84. function existOrMakeToDir(){ //return true if is dir ,or make it
  85.  if(is_dir($this->_cache_to_dir)){
  86.  return TRUE;
  87.  }
  88.  else{
  89.  return @mkdir($this->_cache_to_dir,0700);
  90.  }
  91. }
  92. function show(){
  93.  echo $this->_cached_content;
  94.  if($this->_log_performance){
  95. $this->logToFile();
  96.  }
  97.  exit();
  98. }
  99. function flush(){
  100. }
  101. }
  102. function _cacher_call_back(&$AContent){
  103.  global $_SELF_CACHER;
  104.  $_SELF_CACHER->setCachedContent($AContent);
  105.  $_SELF_CACHER->writeCachedContent();
  106.  return $_SELF_CACHER->_cached_content;
  107. }
  108. if(!isset($_SELF_CACHER))$_SELF_CACHER=&new TSelfCacher;
  109.  
  110. ?>
ikioloak
dlaczego korzystasz z tablicy HTTP_SERVER_VARS? Powinienes zmienic na $_SERVER, ale aktualna sytuacja nie powinna generowac bledow. Usun @. Daj na pczatku skryptu error_reporting(E_ALL) i zobacz czy gdizes sie nie wywraca.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.