手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP Framework

cloudflare 后的 wordpress 如何设置 HTTPS

 这应该是做跨境 wordpress 的人经常遇到了。众所周知,用了 Cloudflare 之后,几乎不用再管 https 的问题。wordpress 当然也是这样。

在后台站点设置网址为 http://xxx.com,就可以正常使用了。在后台配置的时候。网址下面还有一个输入框,是专门用来处理css 之类的,这样外部或者静态链接就可以用下面的网址了。
 
问题也就在这里。
1、如果你只是为了使用 https,那么这样就够了。
2、如果你要设置 API,即开启 application,系统就不让你设置,让你非要支持 https 才行(即siteurl必须要是 https 的)
3、如果你 siteurl 设置为 https,你会发现站点打不开了。
 
如果你不使用xmlrpc 接口,其实 siteurl 设置为 http 就行了,然后在 cloudflare 里将 SSL 设置为灵活就完事。
如果你要支持 xmlrpc,那么 cloudflare 里将 SSL 设置为完全(完全分两种 :完全和完全严格),设置成完全后,siteurl 就可以改成 https 了。
完全这两种有一点区别
共同点:都是要求网站有SSL 证书
不同点:完全可以用自签名证书,完全严格则要求证书可信(可以用 CF 的证书)
然后,在 nginx 或者 apache 里配置好证书就 OK了

laravel whereRaw

 这个标题写出来其实也挺Low的,只是提醒自己一下。有时候真的会忘,之前用Yii用的太多,突然换到Laravel后,很多东西都不记得。

比如表字段比较,Yii的话可能就是table::find()->andWhere(new DbExpression('xxx > xxx'))【不记得写得对不对,不用IDE,现在的框架类都记不清了】。于是换到laravel 的时候我也理所当然的写了 Table::query()->where(DB::raw('xx > yy'));然后发现生成的SQL是 select * from table where xx > yy is null ....我晕。这个is null是什么鬼?

再后面才发现,原来还有whereRaw。。。。只要写Table::query()->whereRaw('xx > yy')。。记一下。有好多类似鬼方法,什么whereHas,whereIn。。。还是Yii方便啊。自动识别数组。。。

黑黑

Yii2 without Bower

 Yii2项目中如何移除Bower库?方法很简单,除了移除fxp插件外,就是利用composer的provide属性

» 阅读全文

Tags: yii2, composer, bower, fxp

Yii2的主从数据库设置

 在yii1的时候,主从数据库的支持没有那么方便,只能写上多个DB的components,然后在AR的getDB中返回相应的db。这样也可以用来对付主从数据库

Yii2则已经解决这个问题,直接在代码中进行处理即可:
PHP代码
  1. 'db' =>[  
  2.      'class' => 'yii\db\Connection',  
  3.   
  4.     // 配置主服务器  
  5.     'dsn' => 'dsn for master server',  
  6.     'username' => 'master',  
  7.     'password' => '',  
  8.     'charset' => 'utf8',  
  9.     'tablePrefix' => 'php_',//默认为空  
  10.   
  11.     // 配置从服务器  
  12.     'slaveConfig' => [  
  13.         'username' => 'slave',  
  14.         'password' => '',  
  15.         'charset' => 'utf8',  
  16.       'tablePrefix' => 'php_',  
  17.         'attributes' => [  
  18.             // use a smaller connection timeout  
  19.             PDO::ATTR_TIMEOUT => 10,  
  20.         ],  
  21.       
  22.     ],  
  23. ];  
是不是感觉超级方便,而不止是这样,你还可以配置从服务器组:
PHP代码
  1. 'db'=>[  
  2.    //...上面是一些标准配置  
  3.     'slaves' => [  
  4.         ['dsn' => 'dsn for slave server 1'],  
  5.         ['dsn' => 'dsn for slave server 2'],  
  6.         ['dsn' => 'dsn for slave server 3'],  
  7.         ['dsn' => 'dsn for slave server 4'],  
  8.     ],   
  9. ]  
更值得称赞的是,主服务器也是多个主服务器的配置就是下面这样,其中字符编码集,表前缀等设置参考上面的。
PHP代码
  1. 'db'=>[  
  2.     // 配置主服务器  
  3.     'masterConfig' => [  
  4.         'username' => 'master',  
  5.         'password' => '',  
  6.         'attributes' => [  
  7.             // use a smaller connection timeout  
  8.             PDO::ATTR_TIMEOUT => 10,  
  9.         ],  
  10.     ],  
  11.   
  12.     // 配置主服务器组  
  13.     'masters' => [  
  14.         ['dsn' => 'dsn for master server 1'],  
  15.         ['dsn' => 'dsn for master server 2'],  
  16.     ],  
  17.     //other ...slaves  
  18. ];  
果然 是轻轻松松啊。
当然 如果你想更轻松的使用,这些,其实就是得用YII2的AR。你就用不着改代码了。。
 
 

Tags: yii2

ssdb的Yii cache扩展

google的leveldb越来越被很多人接受。国内的ideawu基于leveldb还写了一个ssdb的前置扩展用来实现了很多功能,比如标准的getset和hget,hset还有zset,zget,也实现了队列。当然pub/sub就没有办法实现了。毕竟它和redis还是有点区别。

基于标准的ssdb的类,写了个小扩展,扩展了Yii的Cache类:

PHP代码
  1. class CSsdbCache extends CCache  
  2. {  
  3.     /** 
  4.      * @var string hostname to use for connecting to the redis server. Defaults to '127.0.0.1'. 
  5.      */  
  6.     public $hostname = '127.0.0.1';  
  7.     /** 
  8.      * @var int the port to use for connecting to the ssdb server. Default port is 8888. 
  9.      */  
  10.     public $port = 8888;  
  11.     /** 
  12.      * @var float 
  13.      */  
  14.     public $timeout = 2000;  
  15.     public $serializer = false;  
  16.     public $_cache;  
  17.     protected $_cachekeys = 'ssdb_cachekey';  
  18.       
  19.     public function init() {  
  20.         parent::init();  
  21.     }  
  22.     /** 
  23.      * @return SSDB 
  24.      */  
  25.     public function getSsdbCache() {  
  26.         if ($this->_cache !== null)  
  27.             return $this->_cache;  
  28.         else {  
  29.             return $this->_cache = new SimpleSSDB($this->hostname, $this->port, $this->timeout);  
  30.         }  
  31.     }  
  32.     public function getkeys() {  
  33.         return $this->getSsdbCache()->hkeys($this->_cachekeys, """"$this->getSsdbCache()->hsize($this->_cachekeys));  
  34.     }  
  35.     /** 
  36.      * Retrieves a value from cache with a specified key. 
  37.      * This is the implementation of the method declared in the parent class. 
  38.      * @param string $key a unique key identifying the cached value 
  39.      * @return string|boolean the value stored in cache, false if the value is not in the cache or expired. 
  40.      */  
  41.     protected function getValue($key) {  
  42.         return unserialize($this->getSsdbCache()->get($key));  
  43.     }  
  44.   
  45.     /** 
  46.      * Stores a value identified by a key in cache. 
  47.      * This is the implementation of the method declared in the parent class. 
  48.      * @param string  $key    the key identifying the value to be cached 
  49.      * @param string  $value  the value to be cached 
  50.      * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. 
  51.      * @return boolean true if the value is successfully stored into cache, false otherwise 
  52.      */  
  53.     protected function setValue($key$value$expire) {  
  54.         $this->getSsdbCache()->hset($this->_cachekeys, $key, 1);  
  55.         if ($expire > 0) {  
  56.             //$expire += time();  
  57.             return $this->getSsdbCache()->setx($key, serialize($value), (int) $expire);  
  58.         }  
  59.         else {  
  60.             return $this->getSsdbCache()->set($key, serialize($value));  
  61.         }  
  62.     }  
  63.     /** 
  64.      * Stores a value identified by a key into cache if the cache does not contain this key. 
  65.      * This is the implementation of the method declared in the parent class. 
  66.      * @param string  $key    the key identifying the value to be cached 
  67.      * @param string  $value  the value to be cached 
  68.      * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. 
  69.      * @return boolean true if the value is successfully stored into cache, false otherwise 
  70.      */  
  71.     protected function addValue($key$value$expire) {  
  72.         return $this->setValue($key$value$expire);  
  73.     }  
  74.     /** 
  75.      * Deletes a value with the specified key from cache 
  76.      * This is the implementation of the method declared in the parent class. 
  77.      * @param string $key the key of the value to be deleted 
  78.      * @return boolean if no error happens during deletion 
  79.      */  
  80.     protected function deleteValue($key) {  
  81.         $this->getSsdbCache()->hdel($this->_cachekeys, $key);  
  82.         return $this->getSsdbCache()->del($key);  
  83.     }  
  84.     /** 
  85.      * @return boolean whether the flush operation was successful. 
  86.      */  
  87.     protected function flushValues() {  
  88.         $this->getSsdbCache()->multi_del($this->getkeys());  
  89.         return $this->getSsdbCache()->hclear($this->_cachekeys);  
  90.     }  
  91. }  

其实代码很简单,不过由于ssdb默认没有serialize功能,所以在存储之前,得先主动的serialize,然后get的时候unserialize。不然就没有办法存储数组了。

由于ssdb没有flush功能。所以利用hget/hset将所有的key存储下来。flush的时候把hget获取的key读出来删除。然后再清掉这个hget的key

最后还有expire。ssdb里的setx第三个参数。。。居然不是expire,而是ttl。开始的时候,一直都当成expire。结果浪费了很长时间

Tags: yii

Records:6512345678910»