<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace app\crm\command;
class CrmService  extends \Worker{
    protected $method = '';
    function __construct($method) {
        ini_set('zend.enable_gc', true);
        $this->method = $method;
    }
    
    public function run() {
        //根据$this->$method的方法进行执行相应进程操作。
        //$this->synchronized(function($thread){
         $message = new app\crm\lib\Message();
        switch ($this->method){
            case 'test':
                $y = (int)get_rand_string(2, 1);
                for($i=0;$i<$y;$i++){
                    file_put_contents('func1.txt', date('Y-m-d H:i:s').'this loop count:'.$y.';current:'.$i.'.thread:'.\Thread::getCurrentThreadId()."\r\n", FILE_APPEND);
                    sleep(1);
                }

                break;
            case 'test2':
                $y = (int)get_rand_string(1, 1);
                for($i=0;$i<$y;$i++){
                    file_put_contents('func2.txt', date('Y-m-d H:i:s').'this loop count:'.$y.';current:'.$i.'.thread:'.\Thread::getCurrentThreadId()."\r\n", FILE_APPEND);
                    sleep(1);
                    // \throwException('set');
                    //fopen('abc.php', 'r');
                }
                break;
            case 'historydata':
                $res = $message->historyDataRedisList();
                echo $res;
                break;
            default:
                exit(0);
                break;
        };
            
            
       // },$this);
        
        
    }
    

}