stanley-king %!s(int64=8) %!d(string=hai) anos
pai
achega
fdb8a0cdae

+ 5 - 1
core/framework/db/mysqli.php

@@ -52,7 +52,11 @@ class Db
 
 		self::$link[$host] = @new mysqli($conf['dbhost'], $conf['dbuser'], $conf['dbpwd'], $conf['dbname'], $conf['dbport']);
 		self::$connect_time = time();
-		if (mysqli_connect_errno()) throw_exception("Db Error: database connect failed");
+		if (mysqli_connect_errno()) {
+		    $err_no = mysqli_connect_errno();
+		    $error = mysqli_connect_error();
+		    throw_exception("Db Error: database connect failed errno={$err_no} err={$error}");
+        }
 
 		switch (strtoupper($conf['dbcharset']))
 		{

+ 37 - 46
core/framework/libraries/queue.php

@@ -6,19 +6,17 @@
  * @package    
  */
 
-class QueueClient {
-
+class QueueClient
+{
     private static $queuedb;
 
-    /**
-     * 入列
-     * @param string $key
-     * @param array $value
-     */
-    public static function push($key, $value) {
+    public static function push($key, $value)
+    {
         if (!C('queue.open')) {
-            Logic('queue')->$key($value);return;
+            Logic('queue')->$key($value); //如果队列没打开,立即执行
+            return;
         }
+
         if (!is_object(self::$queuedb)) {
             self::$queuedb = new QueueDB();
         }
@@ -26,20 +24,22 @@ class QueueClient {
     }
 }
 
-class QueueServer {
-
+class QueueServer
+{
     private $_queuedb;
     
     public function __construct() {
         $this->_queuedb = new QueueDB();
     }
 
-    /**
-     * 取出队列
-     * @param unknown $key
-     */
-    public function pop($key,$time) {
-        return unserialize($this->_queuedb->pop($key,$time));
+    public function pop($key,$time)
+    {
+        $result = $this->_queuedb->pop($key,$time);
+        if($result != null) {
+            return unserialize($result);
+        } else {
+            return false;
+        }
     }
 
     public function scan() {
@@ -47,44 +47,35 @@ class QueueServer {
     }
 }
 
-class QueueDB {
-
-    //定义对象
+class QueueDB
+{
     private $_redis;
 
-    //存储前缀
     private $_tb_prefix = 'QUEUE_TABLE_';
-
     //存定义存储表的数量,系统会随机分配存储
     private $_tb_num = 2;
 
-    /**
-     * 初始化
-     */
-    public function __construct() {
+    public function __construct()
+    {
         if ( !extension_loaded('redis') ) {
             throw_exception('redis failed to load');
         }
         $this->_redis = new Redis();
         $this->_redis->connect(C('queue.host'),C('queue.port'),20);
+        $this->_redis->setOption(Redis::OPT_READ_TIMEOUT, 120);
     }
 
-    /**
-     * 入列
-     * @param unknown $value
-     */
-    public function push($value) {
+    public function push($value)
+    {
         try {
             return $this->_redis->lPush($this->_tb_prefix.rand(1,$this->_tb_num),$value);
-        }catch(Exception $e) {
+        } catch(Exception $e) {
              throw_exception($e->getMessage());
         }
     }
 
-    /**
-     * 取得所有的list key(表)
-     */
-    public function scan() {
+    public function scan()
+    {
         $list_key = array();
         for($i=1;$i<=$this->_tb_num;$i++) {
             $list_key[] = $this->_tb_prefix.$i;
@@ -92,23 +83,23 @@ class QueueDB {
         return $list_key;
     }
 
-    /**
-     * 出列
-     * @param unknown $key
-     */
-    public function pop($key, $time) {
-        try {
+    public function pop($key, $time)
+    {
+        try
+        {
             if ($result = $this->_redis->brPop($key,$time)) {
                 return $result[1];
             }
         } catch (Exception $e) {
-            exit($e->getMessage());
+            $err = $e->getMessage();
+            $code = $e->getCode();
+            Log::record("QueueDB pop err: code={$code} err={$err}",Log::ERR);
+            return null;
         }
+
+        return null;
     }
 
-    /**
-     * 清空,暂时无用
-     */
     public function clear() {
         $this->_redis->flushAll();
     }

+ 2 - 2
crontab/control/control.php

@@ -13,11 +13,11 @@ defined('InShopNC') or exit('Access Invalid!');
 class BaseCronControl
 {
     public function shutdown(){
-        exit("success at ".date('Y-m-d H:i:s',time())."\n");
+        //exit("shutdown at ".date('Y-m-d H:i:s',time())."\n");
     }
 
     public function __construct(){
-        register_shutdown_function(array($this,"shutdown"));
+        //register_shutdown_function(array($this,"shutdown"));
     }
 
     /**

+ 25 - 6
crontab/control/queue.php

@@ -8,31 +8,48 @@
 
 */
 defined('InShopNC') or exit('Access Invalid!');
-ini_set('default_socket_timeout', -1);
+
+//此行代码会导致bug
+//ini_set('default_socket_timeout', -1);
+
+function sig_handler($signo)
+{
+    switch($signo) {
+        case SIGINT:
+            break;
+        default:
+            break;
+    }
+}
 
 class queueControl extends BaseCronControl
 {
     private $_stop = false;
 
-    public function indexOp() {
+    public function indexOp()
+    {
         if (ob_get_level()) ob_end_clean();
 
-        pcntl_signal(SIGINT, array(&$this,'sig_handler'));
+//        pcntl_signal(SIGINT, array($this,'sig_handler'));
+        pcntl_signal(SIGINT, 'sig_handler');
 
         $logic_queue = Logic('queue');
 
         $worker = new QueueServer();
         $queues = $worker->scan();
 
-        while (true) {
+        while (true)
+        {
             pcntl_signal_dispatch();
 
             if ($this->_stop) {
                 exit;
             }
             $content = $worker->pop($queues,60);
+            if($content == false) continue;
 
-            if (is_array($content)) {
+            if (is_array($content))
+            {
                 $method = key($content);
                 $arg = current($content);
 
@@ -40,7 +57,9 @@ class queueControl extends BaseCronControl
                 if (!$result['state']) {
                     $this->log($result['msg'],false);
                 }
-            } else {
+            }
+            else
+            {
                 $model = Model();
                 $model->checkActive();
                 unset($model);

+ 3 - 12
crontab/index.php

@@ -1,29 +1,20 @@
 <?php
-/**
- * 队列
- *
- *
- * 计划任务触发 by abc.com
- */
+
 
 if (empty($_SERVER['argv'][1])) exit('Access Invalid!');
 
 define('APP_ID','crontab');
 define('BASE_PATH',str_replace('\\','/',dirname(__FILE__)));
 define('TRANS_MASTER',true);
-//if (!@include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');
-//if (!@include(BASE_CORE_PATH.'/33hao.php')) exit('33hao.php isn\'t exists!');
-
 
-//if (PHP_SAPI == 'cli') {
 if (php_sapi_name() == 'cli') {
     $_GET['act'] = $_SERVER['argv'][1];
     $_GET['op'] = empty($_SERVER['argv'][2]) ? 'index' : $_SERVER['argv'][2];
 }
+
 if (!@include(BASE_PATH.'/control/control.php')) exit('control.php isn\'t exists!');
 
 echo "act=" . $_GET['act'] . "\n";
 echo "act=" . $_GET['op'] . "\n";
 
-Base::run();
-?>
+Base::run();

+ 0 - 1
mobile/control/activity.php

@@ -332,7 +332,6 @@ class activityControl extends mobileControl
     public function actingOp()
     {
         $actings = activity_helper::acting();
-//        Log::record("activity::acting count = " . count($actings),Log::DEBUG);
 
         $formater = new act_formater($actings);
         $result = $formater->format_acting();

+ 2 - 0
mobile/control/member_evaluate.php

@@ -271,6 +271,8 @@ class member_evaluateControl extends mbMemberControl
 
             if(!empty($geval_image)) {
                 $evaluate_goods_info['geval_image'] = $geval_image;
+            } else {
+                $evaluate_goods_info['geval_image'] = '';
             }
 
             $evaluate_goods_array[] = $evaluate_goods_info;

+ 1 - 1
test/queueTest.php

@@ -24,7 +24,7 @@ class queueTest extends PHPUnit_Framework_TestCase
         $param['member_id'] = 36490;
         $param['text']      = "红包退还通知:您发送的红包已超过24小时,退还未被领取的金额1234元,请在收支明细中查看.";
         $param['go_type']   = '';
-        Logic('queue')->upushSendMsg($param);
+        QueueClient::push('upushSendMsg',$param);
     }
 
     public static function tearDownAfterClass()