如何在mac上顺利安装php5.5+memcache并且巧妙躲避各种坑

如题所述

第1个回答  2016-12-18
  用mac 做开发环境,封装 Cache,在没用 memcache 扩展的时候,使用 Cache 的时候,使用 file 替代。再生产环境的时候,如果有装 memcache 会自动切换。
  class TL_Cache
  {
  private $_file;
  private $_md5_key;
  private $_md5_val = '';
  private $_mem;
  function __construct($key)
  {
  $this->_md5_key = $key;
  //$ever = 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'.ever';
  $ever = 'var'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'data';
  $ever .= DIRECTORY_SEPARATOR.substr($this->_md5_key, 0, 2);
  $ever .= DIRECTORY_SEPARATOR.substr($this->_md5_key, 2, 2);
  $this->_file = TL_FSO::getMultDir(_ROOT_DIR_, $ever).$this->_md5_key;
  $this->_mem = TL_Mem::getInstance();
  }
  public function get()
  {
  $this->_md5_val = $this->_mem->get($this->_md5_key);
  $res = TL_FSO::getFileContent($this->_file);
  if (!$this->_mem->verify() || $this->_md5_val == md5($res)) {
  return unserialize($res);;
  }
  //error_log('get from cache');
  return null;
  }
  public function set($val)
  {
  $val = serialize($val);
  $this->_mem->set($this->_md5_key, md5($val));
  return TL_FSO::createFile($this->_file, $val);
  }
  public function delete()
  {
  $this->_mem->delete($this->_md5_key);
  TL_FSO::deleteFile($this->_file);
  }
  public function getVal($key)
  {
  return $this->get();
  }
  public function setVal($key, $val)
  {
  return $this->set($val);
  }
  }
第2个回答  2018-06-29
Mac上内置的有Apache和PHP,如果不想用,下个集成环境吧(XAMPP),这样自己控制修改,CI的直接文件复制到指定文件处,就可以用了。有特殊要求的你在去扩展就行。
具体的看CI的使用稳当。

如果你认可我的回答,敬请及时采纳,
~如果你认可我的回答,请及时点击【采纳为满意回答】按钮本回答被网友采纳
第3个回答  2016-12-18

先安装homebrew

官网链接:http://brew.sh/index_zh-cn.html


brew tap homebrew/dupes

brew tap homebrew/versions

brew tap homebrew/homebrew-php

brew install php55

brew install homebrew/php/php55-memcache

第4个回答  2016-12-16
mac的坑要比windows少很多吧,不踩坑是不可能的,你可以死心了
相似回答