异步记录PHP日志

<?php 
$result = array('code' => 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 '不会返回给客户端!';//这里的内容不会返回给客户端

 

Posted in PHP | Leave a comment

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;
    }
}

 

Posted in Nginx, Symfony | Leave a comment

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)
    }
}

 

Posted in Egret | Leave a comment

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);
    }
}

 

Posted in Egret | Leave a comment

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;
    }
}

 

Posted in Egret | Leave a comment