月度归档:2019年07月

golang交叉编译

Windows主机编译Linux,MAC客户端

Windows主机编译Windows客户端

SET CGO_ENABLED=0
SET GOOS=windows
SET GOARCH=amd64
go build -o client-windows.exe main.go

Windows主机编译LINUX客户端

SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
go build -o client-linux main.go

Windows主机编译MAC客户端

SET CGO_ENABLED=0
SET GOOS=darwin
SET GOARCH=amd64
go build -o client-mac main.go

Linux主机编译Widows,MAC客户端

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o client-linux main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o client-mac main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o client-windows.exe main.go

MAC主机编译Widows,linux客户端

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o client-linux main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o client-mac main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o client-windows.exe main.go

PHP7.3 zts(线程安全)编译以及多线程(pthreads)使用

下载PHP

下载地址:https://www.php.net/downloads.php,开始下载:

su root
mkdir tmp
cd tmp
wget https://www.php.net/distributions/php-7.3.7.tar.bz2

编译安装PHP开启线程安全

tar -jxvf php-7.3.7.tar.bz2
cd php-7.3.7
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libicu-devel

编译

./configure \
--prefix=/usr/local/php-7.3.7-ts \
--enable-maintainer-zts \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-bcmath \
--enable-exif \
--enable-intl \
--enable-mbstring \
--enable-pcntl \
--with-pdo-mysql \
--enable-sockets \
--enable-mysqlnd \
--with-gd

然后:

make && make install

更新autoconf

Autoconf version 2.68 or higher is required错误是才需要此步骤

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar -zxvf autoconf-latest.tar.gz 
cd autoconf-2.69/
.configure
make
make install
autoconf --version 

安装pthreads

git clone https://github.com/krakjoe/pthreads.git
cd pthreads
/usr/local/php-7.3.7-ts/bin/phpize
./configure --with-php-config=/usr/local/php-7.3.7-ts/bin/php-config
make
make install

修改 /usr/local/php-7.3.7-ts/lib/php.ini,增加 extension=pthreads

测试pthreads

/usr/local/php-7.3.7-ts/bin/php worker.php

<?php

class MyWorker extends Worker
{
    public $id;
    public $time;

    public function __construct($id, $time)
    {
        $this->id = $id;
        $this->time = $time;
    }

    public function run()
    {
        while (true) {
            echo sprintf(worker %s is running, %s\n, $this->id, date('Y-m-d H:i:s'));
            sleep($this->time);
        }
    }
}

class MyManager
{
    /**
     * @var MyWorker[]
     */
    protected $workers;

    public function add(MyWorker $work)
    {
        $this->workers[$work->id] = $work;
        echo 'add worker' . $work->id . \n;
    }

    public function run()
    {
        foreach ($this->workers as $id => $work) {
            echo 'run worker' . $work->id . \n;
            $work->start();
        }
    }
}

$manager = new MyManager();
$manager->add(new MyWorker('1', 1));
$manager->add(new MyWorker('2', 3));
$manager->run();

nginx access log 记录cgi执行时间

log_format combined_with_time '$remote_addr - $remote_user [$time_local]  '
                     '$request $status $body_bytes_sent '
                     '$http_referer $http_user_agent '
                     '$request_time $upstream_response_time';

access_log  /data/wwwroot/xxxx/vagrant/nginx/log/frontend-access.log combined_with_time;

firebase替代

Google的firebase只能在国外用,且不开源,国内的有野狗、leancloud都是小厂。

参考

PouchDB

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

PouchDB was created to help web developers build applications that work as well offline as they do online.

It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user\’s data in sync no matter where they next login.

var db = new PouchDB('dbname');

db.put({
  _id: 'dave@gmail.com',
  name: 'David',
  age: 69
});

db.changes().on('change', function() {
  console.log('Ch-Ch-Changes');
});

db.replicate.to('http://example.com/mydb');

CouchDB

Apache CouchDB™ lets you access your data where you need it. The Couch Replication Protocol is implemented in a variety of projects and products that span every imaginable computing environment from globally distributed server-clusters, over mobile phones to web browsers.

Store your data safely, on your own servers, or with any leading cloud provider. Your web- and native applications love CouchDB, because it speaks JSON natively and supports binary data for all your data storage needs.

The Couch Replication Protocol lets your data flow seamlessly between server clusters to mobile phones and web browsers, enabling a compelling offline-first user-experience while maintaining high performance and strong reliability. CouchDB comes with a developer-friendly query language, and optionally MapReduce for simple, efficient, and comprehensive data retrieval.

$ curl -X PUT http://127.0.0.1:5984/my_database/001 -d
'{  Name  :  Raju  ,  age  : 23  ,  Designation  :  Designer  }'

{ok:true,id:001,rev:1-1c2fae390fa5475d9b809301bbf3f25e}

gunDB

A realtime, decentralized, offline-first, mutable graph protocol to sync the web. https://gun.eco/docs

<script src=https://cdn.jsdelivr.net/npm/gun/gun.js></script>
<script>
// var Gun = require('gun'); // in NodeJS
// var Gun = require('gun/gun'); // in React
var gun = Gun();

gun.get('mark').put({
  name: Mark,
  email: mark@gunDB.io,
});

gun.get('mark').on(function(data, key){
  console.log(update:, data);
});
</script>

gun官网

RxDB

⛁ A realtime Database for JavaScript Applications https://rxdb.info/

myCollection.insert({
  name: 'foo',
  lastname: 'bar'
});
const query = myCollection
    .find()
    .where('age')
    .gt(18);

Meteor

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node.js and general JavaScript community.

  • Meteor allows you to develop in one language, JavaScript, in all environments: application server, web browser, and mobile device.
  • Meteor uses data on the wire, meaning the server sends data, not HTML, and the client renders it.
  • Meteor embraces the ecosystem, bringing the best parts of the extremely active JavaScript community to you in a careful and considered way.
  • Meteor provides full stack reactivity, allowing your UI to seamlessly reflect the true state of the world with minimal development effort.

Meteor 官网

import { Mongo } from 'meteor/mongo'; 
export const Tasks = new Mongo.Collection('tasks'); 
import { Tasks } from '../api/tasks.js'; 
db.tasks.insert({ text: Hello world!, createdAt: new Date() });

Kinto

Kinto is a minimalist JSON storage service with synchronisation and sharing abilities. It is meant to be easy to use and easy to self-host.

Kinto is used at Mozilla and released under the Apache v2 licence.

http GET https://kinto.dev.mozaws.net/v1/buckets/default/collections/tasks/records \
       -v --auth 'bob:s3cr3t'

Kinto文档

Kinto官网

Hoodie

Hoodie is a free and Open Source Software for building applications for the web and iOS. It is a complete backend for your apps, ready for you to get creative. It works immediately out-of-the-box: develop your frontend code, plug it into Hoodie’s frontend-friendly API and your app is ready.

When you develop it, your app runs locally first, you can then deploy and host it wherever you want to. And if you want to extend Hoodie’s core features, you can check our list of currently available plugins or build plugins yourself.

Hoodie is a noBackend technology — it\’s there for making the lives of frontend developers easier by abstracting away the backend and keeping you from worrying about backends. It gives you Dreamcode: a simple, easy-to-learn-and-implement frontend API built into it. Hoodie is also Offline First, which means that your app users’ data is stored locally by default so your Hoodie-based apps are accessible and usable anytime, independent from your users’ internet connection.

hoodie.store.add({
    type: 'todo-item',
    content: 'Try out hoodie!',
    done: false
})