public function soapServer($request, $response)
 {/*{{{*/
     $postdata = file_get_contents("php://input");
     $function = 'soapServer';
     $this->ioLogRecorder->addLog(XDateTime::now()->toString()." service [{$function}] ".$this->ioLogRecorder->format2SimpleLog($postdata));
     $configs = ProviderConfigFactory::getProviderAppConfigs(PhoneConference::SPTYPE_HUAWEI, TeleConfProvider::APPTYPE_CONF);
     $callbackUrl = $configs['callbackUrl'];
     $server = new SoapServer(null, array('uri' => 'HuaweiConfCallback','location'=>$callbackUrl));
     $server->setClass('HuaweiTeleConfApi');
     try
     {
         $lockName = $this->getLockerName($postdata);
         $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
         $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
         $locker->getLock($lockName);
         $server->handle();
         $locker->releaseLock($lockName);
     }
     catch(Exception $ex)
     {
         $locker->releaseLock($lockName);
     }
     header("HTTP/1.1 202 Accepted");
     header("Content-Type: text/xml;charset=UTF-8");
     return parent::DIRECT_OUTPUT;
 }/*}}}*/
 public function service($request, $response)
 {/*{{{*/
     ob_start();
     $result = $this->callCenterApi->returnSuccess();
     $function = $request->service;
     if(method_exists($this, $function))
     {
         try
         {
             $lockName = $this->getLockerName($request);
             $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
             $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
             $locker->getLock($lockName);
             $result = $this->$function($request,$response);
             $locker->releaseLock($lockName);
         }
         catch(LockException $ex)
         {
             error_log(XDateTime::now()->toString()."并发锁错误 $lockName\n", 3 , $this->logFileName);
         }
         catch(Exception $ex)
         {
             error_log(XDateTime::now()->toString()."释放锁 $lockName\n", 3 , $this->logFileName);
             $locker->releaseLock($lockName);
         }
     }
     echo $result;
     $this->logTxt .= XDateTime::now()->toString().'--->'.print_r($result, true)."\n";
     header('Content-Length: ' . ob_get_length());
     return parent::DIRECT_OUTPUT;
 }/*}}}*/
 public function service($request, $response)
 {/*{{{*/
     ob_start();
     $result = "";
     $function = $request->service;
     if(method_exists($this, $function))
     {
         try
         {
             $lockName = $this->getLockerName($request);
             $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
             $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
             $locker->getLock($lockName);
             $result = $this->$function($request,$response);
             $locker->releaseLock($lockName);
         }
         catch(LockException $ex)
         {
             $this->ioLogRecorder->addLog(XDateTime::now()->toString()."并发锁错误 $lockName\n");
         }
         catch(Exception $ex)
         {
             $locker->releaseLock($lockName);
         }
     }
     echo $result;
     header('Content-Length: ' . ob_get_length());
     return parent::DIRECT_OUTPUT;
 }/*}}}*/
Exemplo n.º 4
0
 public function onTimer()
 {
     if (END_TIME - 1 < time()) {
         $this->close();
         LockUtil::removeLock('wotapipserver');
         die('timelimit!:' . (microtime(true) - END_TIME - 1));
     }
 }
 /**
  * Switches between two modes: the impact and the return 'mode'.
  * 
  * @param	array	event data
  */
 public function execute($data)
 {
     // TODO: remove this passage?
     // lock management
     echo "l";
     do {
         try {
             LockUtil::checkLock($this->ownerID);
             LockUtil::checkLock($this->ofiaraID);
             // everything checked
             break;
         } catch (SystemException $e) {
             echo 'waiting 0.5s because of a lock ...';
             usleep(500000);
         }
     } while (true);
     echo "m";
     LockUtil::setLock($this->ownerID, 10);
     if ($this->ofiaraID) {
         LockUtil::setLock($this->ofiaraID, 10);
     }
     // execute
     $this->initArrays();
     $this->eventData = $data;
     // return
     if ($data['state'] == 1) {
         if (count($this->fleet)) {
             $this->executeReturn();
             $this->sendReturnMessage();
         }
     } else {
         if ($data['state'] == 0) {
             $this->executeImpact();
             $this->sendImpactOwnerMessage();
             $this->sendImpactOfiaraMessage();
         } else {
             $this->executeUnknownEvent();
         }
     }
     // TODO: integrate this in wcf event listener?
     FleetOvent::update($this);
     // lock management
     LockUtil::removeLock($this->ownerID);
     LockUtil::removeLock($this->ofiaraID);
     return;
 }
 public function service($request, $response)
 {/*{{{*/
     ob_start();
     $function = $request->service;
     $result = $this->callCenterApi->responseCmdSucc();
     if(method_exists($this, $function))
     {
         try
         {
             $this->logTxt .= $function;
             $results = $this->xmlToArray(file_get_contents("php://input"));
             if(false == empty($results['ucid']))
             {
                 $lockName = $this->getLockerName($results);
                 $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
                 $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
                 $locker->getLock($lockName);
                 $result = $this->$function($request,$response);
                 $locker->releaseLock($lockName);
             }
             else
             {
                 $result = $this->$function($request,$response);
             }
         }
         catch(LockException $ex)
         {
             $this->logTxt .= XDateTime::now()->toString()." 并发锁错误 $lockName\n";
         }
         catch(Exception $ex)
         {
             $this->logTxt .= XDateTime::now()->toString()." 释放锁 $lockName\n";
             $locker->releaseLock($lockName);
         }
     }
     echo $result;
     $this->logTxt .= XDateTime::now()->toString().'--->'.print_r($result, true)."\n";
     header('Content-Length: ' . ob_get_length());
     return parent::DIRECT_OUTPUT;
 }/*}}}*/
    public function service($request, $response)
    {/*{{{*/
        $function = $request->service;

        //这里用框架的request无法接收指定格式的数据,故用file_get_contents("php://input") by dfy
        $postdata = file_get_contents("php://input");
        $this->ioLogRecorder->addLog(XDateTime::now()->toString()." service [{$function}] ".$this->ioLogRecorder->format2SimpleLog($postdata));

        $postdata = json_decode($postdata, true);
        //需要调试详细日志时打开配置 by hyb
        //$this->printDetailCallbackLog($function, $postdata);

        ob_start();
        //给全时返回的数据
        $result = json_encode(array("statusCode" => '0'));
        if(method_exists($this, $function))
        {
            try
            {
                $lockName = $this->getLockerName($postdata);
                $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
                $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
                $locker->getLock($lockName);
                $this->$function($postdata);
                $locker->releaseLock($lockName);
            }
            catch(LockException $ex)
            {
                $this->ioLogRecorder->addLog(XDateTime::now()->toString()."并发锁错误 $lockName\n");
            }
            catch(Exception $ex)
            {
                $locker->releaseLock($lockName);
            }
        }
        echo $result;
        header('Content-Length: ' . ob_get_length());
        return parent::DIRECT_OUTPUT;
    }/*}}}*/
 private function dealAutoCreatedConfOrder($orderId, $teleConfOwnerId)
 {/*{{{*/
     $lockName = "setconfowner{$orderId}";
     try
     {
         $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
         $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
         $locker->getLock($lockName);
         $confOwnerId = TelOrderClient::getInstance()->updateAdminUser4ConfOwner($teleConfOwnerId, $this->curUser);
         $locker->releaseLock($lockName);
     }
     catch(Exception $ex)
     {
         $locker->releaseLock($lockName);
     }
     return $teleConfOwnerId;
 }/*}}}*/
 /**
  * Removes the lock.
  */
 protected function removeLock()
 {
     if (!$this->removedLock) {
         LockUtil::removeLock(self::LOCK_NAME);
         $this->removedLock = true;
     }
 }
Exemplo n.º 10
0
<?php
/*
 * 功能:更新医生个人空间的sitemap.xml,以便搜索引擎查询,每个月的1号凌晨2:30分进行一次,注意凌晨3点有定时任务
 * 日志位置:/home/avatar/logs/webapps/spacefront/sitemap/exeTime_*
 */
$ROOT = dirname(__FILE__);
include_once($ROOT.'/../assembly.php');
ini_set('memory_limit', '128M');
$configFile = $ROOT.'/../config/config.php';
include_once($configFile);

$locker = LockUtil::factory(LockUtil::LOCK_TYPE_FILE, array('single' => true));
if (false == $locker->getLock(__FILE__)){
    exit;
}

$threadSplitNum = 10; //运行的php程序个数
system('sh '.$ROOT.'/createDataDirectory.sh');
$logPath = $ROOT.'/../root/logs/sitemap';
$spaceTotal = SpaceClient::getInstance()->getTotalComfirmedDoctor('Space'); //获得总大小
$pageSize = ceil($spaceTotal / $threadSplitNum);
$curPage = $threadSplitNum;
for(;$curPage > 0; --$curPage ){
	system("/usr/bin/nohup /Data/apps/php/bin/php {$ROOT}/updatedoctorsitemap.php {$curPage} {$pageSize} >> {$logPath}/exeTime_{$curPage}.log &");
}
$locker->releaseLock(__FILE__);
	
Exemplo n.º 11
0
    private function anaPostData($request,$response)
    {/*{{{*/
        //get post data, May be due to the different environments
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        if (!empty($postStr))
        {
           //保存数据
           $weixPostData = WeixClient::getInstance()->addWeixPostData($postStr, WeixUser::WEIXINTYPE_PATIENT);
           $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

           $lockName = $postObj->FromUserName;  //微信的openid
           try
           {
               $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
               $locker  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
               $locker->getLock($lockName);
               $this->dealPostData($postObj);
               $locker->releaseLock($lockName);
           }
           catch(Exception $ex)
           {
               $locker->releaseLock($lockName);
           }
        }
        else 
        {
            echo mb_convert_encoding("你啥也没说", 'utf-8','auto');
        }
        exit;
    }/*}}}*/
Exemplo n.º 12
0
    public function run($configs)
    {/*{{{*/
        $result = array();
        $result['errno'] = -1;
        $result['data'] = array();
        try
        {
            BeanFinder::register('configs', new Configuration($configs));
            $this->initDebug();
            Logger::setUp($configs['system']);
            BeanFinder::get('debug')->begin('service', $this->service.'::'.$this->do, true);

            //是否需要进程间同步
            $synchronized = isset($this->options['synchronized'])?$this->options['synchronized']:false;
            if ($synchronized)
            {
                $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
                $lockUtil  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
                $lockName = $this->service.$this->do;

                //client来决定同步标志,同一个方法,可以根据不用的标志来实施不同的锁
                //同一个service,synchronizedKey 不能重复
                $synchronizedKey = isset($this->options['synchronizedKey'])?$this->options['synchronizedKey']:false;
                if ($synchronizedKey)
                {
                    $lockName = $this->service.':'.$synchronizedKey;
                }
                $lockName = strtolower($lockName);
                $lockUtil->getLock($lockName, 10);
            }

            $uw = new UnitOfWork();
            $service = new $this->service;
            $service->initialize($this->options);
            $this->checkMethod($service);
            

            //error_log("files: ".print_r($_FILES, true), 3, '/tmp/a');
            //error_log("args: ".print_r($this->args, true), 3, '/tmp/a');
            //error_log("service: ".print_r($service, true), 3, '/tmp/a');
            //error_log("do: ".print_r($this->do, true), 3, '/tmp/a');
            //error_log("options: ".print_r($this->options, true), 3, '/tmp/a');
            $result['data'] = call_user_func_array(array($service, $this->do), $this->args);

            $uw->commit();

            BeanFinder::get('debug')->end();
            $result = $this->terminateDebug($result);

            $service->terminate();

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            $uw = $service = null;
            $this->checkOutput($result['data']);
            $result['errno'] = 0;
        }
        catch (LockException $e)
        {
            $result['errmsg']  = 'LockTimeOut';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (BizException $e)
        {
            $result['errmsg']  = $e->getMessage();
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            //error_log(print_r($e, true), 3, '/tmp/exception_biz.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (SystemException $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (CustomException $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r($e->errorMessage(), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (Exception $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        return $this->prepareOutput($result);
    }/*}}}*/
Exemplo n.º 13
0
do {
    $locked = false;
    // check
    try {
        LockUtil::checkLock('wotapipserver');
    } catch (SystemException $e) {
        echo 'l';
        $locked = true;
        // wait 0.05s
        usleep(50000);
        // remove if waiting 15s already
        if (time() - TIME_NOW > 15) {
            LockUtil::removeLock('wotapipserver');
            echo 'removed lock';
        }
    }
} while ($locked);
LockUtil::setLock('wotapipserver', END_TIME + 5);
// load
require_once LW_DIR . 'lib/system/io/socket/WOTAPIServer.class.php';
require_once LW_DIR . 'lib/system/io/socket/WOTAPIServerClient.class.php';
require_once WCF_DIR . 'lib/system/io/socket/SocketDaemon.class.php';
if (!defined('WOTAPI_PORT')) {
    define('WOTAPI_PORT', 57154);
}
if (!defined('CRYPTER_KEY')) {
    define('CRYPTER_KEY', base64_decode('SAG ICH NICHT'));
}
// fire
$server = SocketDaemon::createServer('WOTAPIServer', 'WOTAPIServerClient', 0, WOTAPI_PORT);
SocketDaemon::process();
Exemplo n.º 14
0
// include basic ugamela files
include $ugamela_root_path . 'includes/debug.class.' . $phpEx;
$debug = new debug();
include $ugamela_root_path . 'includes/constants.' . $phpEx;
include $ugamela_root_path . 'includes/functions.' . $phpEx;
include $ugamela_root_path . 'includes/vars.' . $phpEx;
include $ugamela_root_path . 'includes/db.' . $phpEx;
if (!defined('NO_PLANET_MAKER')) {
    include $ugamela_root_path . 'includes/planet_maker.' . $phpEx;
}
include $ugamela_root_path . 'includes/rank_maker.' . $phpEx;
include $ugamela_root_path . 'includes/strings.' . $phpEx;
include $ugamela_root_path . "language/" . DEFAULT_LANG . "/lang_info.cfg";
// load config
$result = WCF::getDB()->sendQuery("SELECT * FROM ugml_config");
while ($row = WCF::getDB()->fetchArray($result)) {
    $game_config[$row['config_name']] = $row['config_value'];
}
// calc resources/check hangar production
if (WCF::getUser()->userID) {
    LWCore::getPlanet()->calculateResources();
    //auto logout if ip differs or last onlinetime 12 hours past
    /*if(WCF::getUser()->onlinetime+60*60*12 <= TIME_NOW) {
    		LWCore::logout();
    		die('<meta http-equiv="Refresh" content="1; URL=index.htm"><script>javascript:top.location.href="index.htm"</script>');
    	}*/
}
// global locking
if ($userID > 0) {
    LockUtil::removeLock('global_' . $userID);
}
Exemplo n.º 15
0
 /**
  * Inserts the fleet
  */
 public function fire()
 {
     LockUtil::checkLock(WCF::getUser()->userID);
     LockUtil::setLock(WCF::getUser()->userID, 10);
     EventHandler::fireAction($this, 'shouldFire');
     $this->fleetEditor = FleetEditor::create($this->startPlanetID, $this->endPlanetID, $this->ships, $this->galaxy, $this->system, $this->planet, $this->metal, $this->crystal, $this->deuterium, $this->getDuration(), $this->missionID);
     $planet = Planet::getInstance($this->startPlanetID);
     $planet->getEditor()->changeResources(-$this->metal, -$this->crystal, -($this->deuterium + $this->getConsumption()));
     $ships = array();
     foreach ($this->ships as $specID => $shipCount) {
         $ships[$specID] = -$shipCount;
     }
     $planet->getEditor()->changeLevel($ships);
     // TODO: integrate in wcf eventlistener didFire@FleetQueue
     if ($this->missionID == 11) {
         $formation = new NavalFormation($this->formationID);
         $formation->getEditor()->addFleet($this->fleetEditor->fleetID);
     }
     if ($this->missionID == 12) {
         $standByTime = intval(@$_REQUEST['standByTime']);
         $wakeUpTime = $this->fleetEditor->impactTime + $standByTime;
         $newReturnTime = $this->fleetEditor->returnTime + $standByTime;
         $this->fleetEditor->changeTime(array('return' => $newReturnTime));
         $wakeUpEvent = WOTEventEditor::create(1, $this->fleetEditor->fleetID, array('state' => 2), $wakeUpTime);
         $this->fleetEditor->update(array('wakeUpEventID' => $wakeUpEvent->eventID, 'wakeUpTime' => $wakeUpTime));
     }
     if (WCF::getUser()->userID == 1) {
         FleetOvent::create($this->fleetEditor, false, true);
     }
     EventHandler::fireAction($this, 'didFire');
     $this->deleteFleetQueue();
     LockUtil::removeLock(WCF::getUser()->userID);
 }