var_export 掉咋天

时间:2025-01-28 10:34:32

var_export     文件缓存经常使用    输出或返回一个变量的字符串表示

  1. /**
  2. * 写入缓存
  3. *
  4. * @param string $id
  5. * @param mixed $data
  6. * @param array $policy
  7. */
  8. public function set($mode, $id, $data, $expired = -1)
  9. {
  10. if( empty($mode) || empty($id) ){return false;}
  11. $path = $this->getComFilename($mode ,$id);
  12. $expired = ($expired < 0) ? -1 : time() + $expired;
  13. $content = array(
  14. 'expired' => $expired,
  15. 'data'    => $data,
  16. );
  17. $content = '<?php return ' . var_export($content, true) . ';';
  18. // 写入缓存,并去掉多余空格
  19. file_put_contents($path, $content, LOCK_EX);
  20. // file_put_contents($path, php_strip_whitespace($path), LOCK_EX);
  21. clearstatcache();
  22. $this->_cachelist($path,$mode);//写缓存列表文件
  23. return true;
  24. }