异步记录PHP日志

 1, 'message' => '请求成功');
echo json_encode($result);
$message = '这是变量内容';
//投递日志开始,只有FPM模块才有
if(function_exists('fastcgi_finish_request'))
{
    fastcgi_finish_request();
}
sleep(1);//即使加了sleep也不影响原有逻辑执行
file_put_contents('/tmp/log.txt', date('Y-m-d H:i:s') . $message . " 日志内容1\n" , FILE_APPEND);
sleep(1);
file_put_contents('/tmp/log.txt', date('Y-m-d H:i:s') . $message .  " 日志内容2\n", FILE_APPEND);

echo '不会返回给客户端!';//这里的内容不会返回给客户端

 

nginx配置Symfony

server {
    listen       80;
    server_name  blog.phpfs.com;
    root   /data/web;
    rewrite ^/app\.php/?(.*)$ /$1 permanent;
    location / {
        index app.php;
        try_files $uri @rewriteapp;
    }
    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }
    index  index.html index.htm index.php app.php;
    location ~ \.php {
        fastcgi_pass unix:/dev/shm/php5-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /\.ht {
        deny  all;
    }
}

 

Egret之List使用示例

class Main extends egret.DisplayObjectContainer{
    public constructor()
    {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }
    private list: eui.List;
    public onAddToStage(event: egret.Event): void
    {
        var exml = `
          `;
        var list = new eui.List();
        list.dataProvider = new eui.ArrayCollection(["item1","item2","item3"]);
        list.itemRendererSkinName = exml;
        this.addChild(list);
        this.list = list;
        list.selectedIndex = 1;//设置默认选中项

        list.allowMultipleSelection = true;//开启多选
        list.requireSelection = true;//至少选择一个
        list.addEventListener(eui.ItemTapEvent.ITEM_TAP,this.onChange,this);

    }
    private onChange(e: eui.PropertyEvent): void
    {
        //获取点击消息
        console.log(this.list.selectedItem,this.list.selectedIndex)
    }
}

 

ArrayCollection使用说明


class Main extends egret.DisplayObjectContainer{
    public constructor()
    {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }

    public onAddToStage(event: egret.Event): void
    {
        //先创建一个数组
        var sourceArr: any[] = [{ name: "one",value: 1 },{ name: "two",value: 2 }];
        //用ArrayCollection包装
        var myCollection: eui.ArrayCollection = new eui.ArrayCollection(sourceArr);

        //当数据改变的时候,ArrayCollection会派发事件
        myCollection.addEventListener(eui.CollectionEvent.COLLECTION_CHANGE,this.collectionChangeHandler,this);

        var itemData: Object = { name: "three",value: 3 };
        myCollection.addItem(itemData);//相当于push
        myCollection.addItemAt({ name: "zero",value: 0 },0);//添加的指定的索引位置

        myCollection.replaceItemAt({ name: "zero",value: -1 },0);

        //获取
        console.log(myCollection.getItemAt(0).name);//根据索引位置获取某一项数据
        console.log(myCollection.getItemIndex(itemData));//获取某一项数据所在的索引值
        console.log(myCollection.length);//获取数组长度

        myCollection.removeItemAt(0);//删除某一个
        myCollection.removeAll();//全部删除
        
    }
    
    private collectionChangeHandler(evt: eui.CollectionEvent): void
    {
        console.log("数据已改变:" + evt.kind + "," + evt.target.length);
    }
}

 

Egret语法DataGroup使用案例

class Main extends egret.DisplayObjectContainer{
    public constructor()
    {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }

    public onAddToStage(event: egret.Event): void
    {
        //先创建一个数组
        var sourceArr: any[] = [];
        for(var i: number = 1;i < 5;i++)
        {
            sourceArr.push({ label: "item" + i,num: "num=" + Math.ceil(Math.random() * 100)});
        }
        //用ArrayCollection包装
        var myCollection: eui.ArrayCollection = new eui.ArrayCollection(sourceArr);
        var dataGroup: eui.DataGroup = new eui.DataGroup();
        dataGroup.dataProvider = myCollection;
        dataGroup.percentWidth = 100;
        dataGroup.percentHeight = 100;
        dataGroup.useVirtualLayout = true;//性能优化,避免创建过多对象实例
        dataGroup.itemRenderer = LabelRenderer;
        this.addChild(dataGroup);
        
    }
}
//类LabelRenderer一定要继承eui.ItemRenderer
class LabelRenderer extends eui.ItemRenderer
{
    private labelDisplay: eui.Label;
    public constructor()
    {
        super();
        this.touchChildren = true;
        this.labelDisplay = new eui.Label();
        this.addChild(this.labelDisplay);
    }
    protected dataChanged(): void
    {
        this.labelDisplay.text = this.data.label + " "+ this.data.num;
    }
}

 

TS调用JS方法

在TS文件最上方声明
declare function closeView(): void;
然后编写js文件resource/js/main.js
function closeView() {
    self.close();
}
然后要在界面引入js文件

这样ts文件就可以直接用closeView方法了

 

egret自定义loadingUI

class LoadingUI extends egret.Sprite{
    
    private textField:egret.TextField;
    public constructor()
    {
        super();
        RES.getResByUrl('resource/assets/loading.png',this.onComplete,this,RES.ResourceItem.TYPE_IMAGE);
    }
    private onComplete(event:any):void {
        var img: egret.Texture = event;
        var bitmap: egret.Bitmap = new egret.Bitmap(img);
        this.addChild(bitmap);
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.x = (this.width - this.textField.width)/2;
        this.textField.y = (this.height - 80);
        this.textField.textAlign = "center";
    }

    public setProgress(current, total):void {
        this.textField.text = "游戏加载中" + current + "/" + total;
    }
}

 

mac执行vagrant命令报错

执行:vagrant box add命令

错误提示:

An error occurred while downloading the remote file. The error

message, if any, is reproduced below. Please fix this error and try

again.

解决办法:sudo rm /opt/vagrant/embedded/bin/curl

执行:vagrant up报错

An error occurred while downloading the remote file. The error

message, if any, is reproduced below. Please fix this error and try

again.

解决办法:

vagrant plugin install vagrant-hostsupdater

然后检查

config.vm.box是否是新增的box名字