Error Array to string conversion for Yii::$app->user->id

解决方法如下:

  1. ALTER TABLE `user` ADD PRIMARY KEY(`id`);
  2. i remove manually from the browser the cookie and it work.

参考:

https://stackoverflow.com/questions/44499961/error-array-to-string-conversion-for-yiiapp-user-id

https://github.com/yiisoft/yii2/issues/1029

https://stackoverflow.com/questions/27681505/login-on-production-server-doesnt-work

解决mac下的Sourcetree每次拉取提交都需要输入密码

Mac使用SourceTree项目的GIT密码始终保存不到Mac的钥匙串中,明明在钥匙串中是存在的.但是在使用sourceTree pull/push代码的时候还是需要再输入密码,很是繁琐.

于是,网上搜索了一下,说的在https模式下,Mac需要使用osxkeychain凭据助手,并在Git中设置使用. 并且如果已经安装了brew的应该会自带了osxkeychain.但是奇怪的是,我安装了brew的,使用brew安装应用也没有问题.那就只能手动的再设置一次了.

使用方法

  1. 先使用命令下载 git-credential-osxkeychain
    curl http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain -o git-credential-osxkeychain
  2. git-credential-osxkeychain 放入 bin目录
    mv git-credential-osxkeychain /usr/local/bin
  3. git-credential-osxkeychain赋权限
    chmod u+x /usr/local/bin/git-credential-osxkeychain
  4. 在Git全局配置中进行设置(也可以在某一个项目里面设置):
    git config --global credential.helper osxkeychain

经过上面的设置,下次访问https的项目时只需要输入一次密码,就会存储到osx的钥匙串中了,以后再也不会在Git中询问了.

HTML5 Canvas转化成图片后上传服务器

function b64ToUint8Array(b64Image) {
   var img = atob(b64Image.split(',')[1]);
   var img_buffer = [];
   var i = 0;
   while (i < img.length) {
      img_buffer.push(img.charCodeAt(i));
      i++;
   }
   return new Uint8Array(img_buffer);
}

var b64Image = canvas.toDataURL('image/jpeg');
var u8Image  = b64ToUint8Array(b64Image);

var formData = new FormData();
formData.append("image", new Blob([ u8Image ], {type: "image/jpg"}));

var xhr = new XMLHttpRequest();
xhr.open("POST", "/api/upload", true);
xhr.send(formData);

用上面这种方式在前端通过js处理,server端不需要进行任何额外处理。

我认为是最方便最直接的办法,反而很多高赞回复,需要server进行各种处理,不推荐。

Had to convert canvas Base64-encoded image to Uint8Array Blob.

 

参考:https://stackoverflow.com/questions/13198131/how-to-save-an-html5-canvas-as-an-image-on-a-server

WordPress定期出现“建立数据库连接时出错”问题的解决方案

配置比较低的虚拟主机,不管是搭在CentOS还是Ubuntu上,Wordpress都会定期出现“建立数据库连接时错误”,那是因为PHP-FPM子进程过多,吃光了内存,MySQL的进程就被干掉了。

通过 netstat -tunlp 发现是MySQL的进程被干掉了,如果service mysqld restart 还重启不了,简单粗暴点就直接reboot。

解决方案
编辑 php-fpm.conf 文件,控制PHP-FPM的子进程数。
1、找到php安装目录etc目录下的 php-fpm.conf 文件:
vim /etc/php-fpm.d/www.conf
2、找到 pm 、pm.start_servers 、pm.min_spare_servers 、pm.max_spare_servers 这几项参数,修改参数的值。
pm = dynamic #php-fpm以动态模式运行,动态模式适合内存较小的服务器
pm.start_servers = 3 #动态模式下,php-fpm的起始进程数
pm.min_spare_servers = 3 #动态模式下,php-fpm的最小进程数
pm.max_spare_servers = 10 #动态模式下,php-fpm的最大进程数
3、重启php-fpm
service php-fpm restart

参考:

https://www.centos.bz/2017/12/wordpress%E5%AE%9A%E6%9C%9F%E5%87%BA%E7%8E%B0%E5%BB%BA%E7%AB%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%97%B6%E5%87%BA%E9%94%99%E9%97%AE%E9%A2%98%E7%9A%84%E8%A7%A3%E5%86%B3/
https://www.simcf.cc/4671.html


Mac上git和sourcetree使用终端代理访问被不可描述的主机

自己的部署的Git服务器被不可描述了。由于没有VPN,只有代理服务器V2Ray和SSR,因此需要通过命令行代理来Push代码。

通过命令行启动Sourcetree:/Applications/Sourcetree.app/Contents/MacOS/Sourcetree就可以通过代理访问网络啦!

方法1:
在终端中直接运行命令
export http_proxy=http://proxyAddress:port
这个办法的好处是简单直接,并且影响面很小(只对当前终端有效,退出就不行了)。
如果你用的是ss代理,在当前终端运行以下命令,那么wget curl 这类网络命令都会经过ss代理
export ALL_PROXY=socks5://127.0.0.1:1080

方法2:
把代理服务器地址写入shell配置文件.bashrc或者.zshrc 或者.bash_profile
直接在.bashrc或者.zshrc或者.bash_profile添加下面内容
export http_proxy=”http://localhost:port”
export https_proxy=”http://localhost:port”
以使用shadowsocks代理为例,ss的代理端口为1080,那么应该设置为
export http_proxy=”socks5://127.0.0.1:1080″
export https_proxy=”socks5://127.0.0.1:1080″
或者直接设置
ALL_PROXYexport ALL_PROXY=socks5://127.0.0.1:1080
localhost就是一个域名,域名默认指向 127.0.0.1,两者是一样的。

然后ESC后:wq保存文件,接着在终端中执行source ~/.bashrc
或者退出当前终端再起一个终端。
这个办法的好处是把代理服务器永久保存了,下次就可以直接用了。或者通过设置alias简写来简化操作,每次要用的时候输入setproxy,不用了就unsetproxy。

alias setproxy=”export ALL_PROXY=socks5://127.0.0.1:1080″
alias unsetproxy=”unset ALL_PROXY”
alias ip=”curl -i http://ip.cn”

命令行测试如下:
MacBook:srv gavin$ setproxy
MacBook:srv gavin$ git push
Everything up-to-date
MacBook:srv gavin$ unsetproxy
MacBook:srv gavin$ git push
fatal: unable to access ‘http://xxx/srv.git/’: Failed to connect to xxx port xx: Operation timed out

方法3:
改相应工具的配置,比如apt的配置sudo vim /etc/apt/apt.conf
在文件末尾加入下面这行
Acquire::http::Proxy “http://proxyAddress:port”
保存apt.conf文件即可。

方法4:
利用proxychains在终端使用socks5代理

补充:如果代理服务器需要登陆,这时可以直接把用户名和密码写进去http_proxy=http://userName:password@proxyAddress:port

参考: https://blog.fazero.me/2015/09/15/%E8%AE%A9%E7%BB%88%E7%AB%AF%E8%B5%B0%E4%BB%A3%E7%90%86%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95/