示例#1
0
 protected final function spawnTask($concurrentNum)
 {
     $childPids = array();
     for ($i = 0; $i < $concurrentNum; $i++) {
         $childPid = pcntl_fork();
         if ($childPid == -1) {
             Log::fatal('cli - fork fail!');
             exit;
         } else {
             if ($childPid > 0) {
                 // parent
                 $childPids[] = $childPid;
             } else {
                 // child
                 $this->run($i);
                 exit;
             }
         }
     }
     foreach ($childPids as $childPid) {
         $status = 0;
         pcntl_waitpid($childPid, $status);
     }
 }
示例#2
0
 private static function genCategoryId($categoryId)
 {
     $level1 = (int) ($categoryId / 1000000);
     $level2 = (int) ((int) ($categoryId / 1000) % 1000);
     $level3 = (int) ($categoryId % 1000);
     if ($level1 == 0) {
         // 增加一级分类
         $sql = 'select max(category_id) as m from g_category';
         $ret = DB::getDB('w')->rawQuery($sql);
         if ($ret === false) {
             return false;
         }
         if (empty($ret) || empty($ret[0]['m'])) {
             return 100000000;
             // 初始以100000000开始,虽然会少用9个,但会整齐好看一些
         }
         $max = (int) $ret[0]['m'];
         if ((int) ($max / 1000000) == 999) {
             Log::fatal('category_id ' . $categoryId . ' level1 max = 999, out of limit!');
             return false;
         }
         return ((int) ($max / 1000000) + 1) * 1000000;
     } else {
         if ($level2 == 0 && $level3 == 0) {
             // 增加二级分类
             $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . $level1 * 1000000 . ' and category_id < ' . ($level1 + 1) * 1000000;
             $ret = DB::getDB('w')->rawQuery($sql);
             if ($ret === false) {
                 return false;
             }
             if (empty($ret) || empty($ret[0]['m'])) {
                 return $level1 * 1000000 + 1000;
             }
             $maxLevel2 = (int) ((int) $ret[0]['m'] / 1000) % 1000;
             if ($maxLevel2 == 999) {
                 Log::fatal('category_id ' . $categoryId . ' level2 max = 999, out of limit!');
                 return false;
             }
             return $level1 * 1000000 + ($maxLevel2 + 1) * 1000;
         } else {
             if ($level3 == 0) {
                 // 增加三级分类
                 $sql = 'select max(category_id) as m from g_category where' . ' category_id >= ' . ($level1 * 1000000 + $level2 * 1000) . ' and category_id < ' . ($level1 * 1000000 + ($level2 + 1) * 1000);
                 $ret = DB::getDB('w')->rawQuery($sql);
                 if ($ret === false) {
                     return false;
                 }
                 if (empty($ret) || empty($ret[0]['m'])) {
                     return $level1 * 1000000 + $level2 * 1000 + 1;
                 }
                 $maxLevel3 = (int) $ret[0]['m'] % 1000;
                 if ($maxLevel3 == 999) {
                     Log::fatal('category_id ' . $categoryId . ' level3 max = 999, out of limit!');
                     return false;
                 }
                 return $level1 * 1000000 + $level2 * 1000 + $maxLevel3 + 1;
             }
         }
     }
     Log::error('error category_id(' . $categoryId . ') when generate category id');
     return false;
 }
示例#3
0
文件: SMS.php 项目: noikiy/php
 public static function secondSend($smsPhones, $smsContent)
 {
     $smsUser = urlencode('xxxx');
     // TODO
     $smsPasswd = urlencode('xxx');
     // TODO
     $now = time();
     $smsSendtime = $now;
     $url = 'http://sms.ensms.com:8080/sendsms/?username='******'&pwd=' . md5($smsUser . $smsPasswd . $smsSendtime) . '&dt=' . $now . '&msg=' . urlencode(self::SMS_TAG . $smsContent) . '&mobiles=' . urlencode($smsPhones) . '&code=';
     $beginTime = microtime(true);
     $ret = HttpUtil::request($url, false, false, 3);
     $diff = round(microtime(true) - $beginTime, 3);
     if ((double) $diff > 1.5) {
         Log::warng('first smservice - escape long time ' . $diff);
     }
     if ($ret === false) {
         return false;
     }
     $ret = intval($ret);
     if ($ret != 0) {
         $state = '接口发回:';
         switch ($ret) {
             case -1:
                 $state .= '一次发送的手机号码过多';
                 break;
             case -2:
                 $state .= '登录账户错误';
                 break;
             case -3:
                 $state .= '密码错误';
                 break;
             case -4:
                 $state .= '余额不足 ';
                 AsyncModel::monitor('短信余额不足', '备用短信运营商余额不足');
                 break;
             case -5:
                 $state .= '超时[注意检查服务器系统时间]';
                 break;
             case -6:
                 $state .= 'code参数不合法';
                 break;
             case -7:
                 $state .= '用成POST了,正确应该是GET';
                 break;
             case -8:
                 $state .= 'username参数丢失';
                 break;
             case -9:
                 $state .= 'pwd参数丢失';
                 break;
             case -10:
                 $state .= 'msg参数丢失 或者 msg为空信息 或 msg 编码不对';
                 break;
             case -11:
                 $state .= 'mobiles参数丢失';
                 break;
             case -12:
                 $state .= 'dt参数丢失';
                 break;
             case -13:
                 $state .= '一次下发短信超过了400个字';
                 break;
             case -14:
                 $state .= 'mobiles参数不对 不是正确电话号';
                 break;
         }
         Log::fatal('sms - ' . $state);
         return false;
     }
     return true;
 }