function push()
 {
     $tqMgr = BaeTaskQueueManager::getInstance();
     if (NULL == $tqMgr) {
         return false;
     }
     $qName = 'testQueue';
     $tq = $tqMgr->create($qName, BaeTaskQueueManager::QUEUE_FETCHURL);
     if (is_null($tq)) {
         return false;
     }
     foreach ($this->arrTask as $url) {
         $task = array(BaeTaskQueue::FETCHURL_URL => $url);
         $tq->push($task);
     }
     $tqMgr->remove($qName);
     return false;
 }
Example #2
0
 /**
  * 获取基础服务
  * @param string $servername  调用的服务名称
  * @param string $config  映射名称,默认为default
  * @return class
  */
 public function server($servername, &$config)
 {
     switch ($servername) {
         case 'cache':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/cache
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeMemcache.class.php';
             return new BaeMemcache();
         case 'count':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/counter
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeCounter.class.php';
             return new BaeCounter();
         case 'rank':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/rank
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeRankManager.class.php';
             return BaeRankManager::getInstance();
         case 'database':
             if (!$this->isCloudSelf()) {
                 return false;
             }
             switch ($config['drive']) {
                 case 'mysql':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/mysql
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
                     $config['user'] = $this->accesskey;
                     $config['pass'] = $this->securekey;
                     break;
                 case 'mongodb':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/mongodb
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_MONGO_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_MONGO_PORT');
                     $config['user'] = $this->accesskey;
                     $config['pass'] = $this->securekey;
                     break;
                 case 'redis':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/redis
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_REDIS_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_REDIS_PORT');
                     $config['pass'] = $this->accesskey . '-' . $this->securekey . '' . $config['dbname'];
                     break;
             }
             break;
         case 'template':
             if (!$this->isCloudSelf()) {
                 return false;
             }
             switch ($config['drive']) {
                 case 'smarty':
                     $config['compile_dir'] = '%template/';
                     $config['cache_dir'] = '%cache/';
                     unset($config['platform']);
                     break;
             }
             break;
         case 'log':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/log
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeLog.class.php';
             /*
             //打印一条警告日志,包括日志级别和日志内容
             $logger ->logWrite(2, "this is for warning log print ");
             //打印一条轨迹日志
             $logger ->logTrace("this is for trace log print ");
             //打印一条通知日志
             $logger ->logNotice("this is for notice log print ");
             //打印一条调试日志
             $logger ->logDebug("this is for debug log print ");
             //打印一条警告日志
             $logger ->logWarning("this is for warning log print ");
             //打印一条致命日志
             $logger ->logFatal("this is for fatal log print ");
             */
             return BaeLog::getInstance();
         case 'image':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/image
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeImageService.class.php';
             return new FN_platform_baeimage();
         case 'vcode':
             //是image服务中的一款,但操作方式所以独立出来
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/image#.E9.AA.8C.E8.AF.81.E7.A0.81.E5.8A.9F.E8.83.BD.EF.BC.88.E5.8F.AA.E6.94.AF.E6.8C.81.E5.8F.82.E6.95.B0.E6.95.B0.E7.BB.84.E6.96.B9.E5.BC.8F.EF.BC.89
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeImageService.class.php';
             return new FN_platform_baeVCode();
         case 'taskqueue':
             //异步操作,一对一
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/taskqueue
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeTaskQueueManager.class.php';
             return BaeTaskQueueManager::getInstance();
         case 'storage':
             //BCS云存储
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/stor/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeStorage($config);
         case 'queue':
             //云消息,异步操作,多对多
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/mq/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeQueue($config);
         case 'mail':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/mq/api#mail
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeMail($config);
         case 'channel':
             //云推送
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/push/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeChannel($config);
         case 'map':
             //LBS地图
             //http://lbsyun.baidu.com/
             return false;
     }
 }