解决方案 »

  1.   

    正好我做了一个这个功能, 不过我不知道其他人怎么做的。 不知道我这种方法是不是最正确的。 
          //如果存在之前输入的天气
          if(file_exists('weather'.$this->getRequest('tousername').'.txt')){
            if(@file_get_contents('weather'.$this->getRequest('tousername').'.txt')=='1'){
              /**/
              require('weather.php');
              $weather_replace_arr = array('天气','市','预报','-',' ');
              $weather_keyword = str_replace($weather_replace_arr, '', $keyword);
              $keys = array_search($weather_keyword, $weatherArr);
              if($keys>0){
                $wea = file_get_contents('http://www.weather.com.cn/data/sk/'.$keys.'.html');
                $wea = json_decode($wea);
                $wea = $wea->weatherinfo;
                $strword = $wea->city. '当前温度:'.$wea->temp.','. $wea->WD . $wea->WS.'发布时间:'.$wea->time;
              }else{
                $strword = $weather_keyword . '的天气查询不到'."\n你可以直接输入天气南昌的形式查询天气或者用刚刚的交互模式";
              }
              /**/
              //$strword= $keyword.'good';
              file_put_contents('weather'.$this->getRequest('tousername').'.txt', '0');
            }
          }
          
          //判断是否是查询天气预报
          $weather_keyword= ' '.$keyword;
          if(strpos($weather_keyword, '天气')==1){
            require('weather.php');
            $weather_replace_arr = array('天气','市','预报','-',' ');
            $weather_keyword = str_replace($weather_replace_arr, '', $weather_keyword);
            
            //如果只输入天气二字,则提示再输入城市
            if($weather_keyword==''){
              $strword = '请输入需要查询的城市名';
              // store session data
              @file_put_contents('weather'.$this->getRequest('tousername').'.txt', '1');
            }else{
              $keys = array_search($weather_keyword, $weatherArr);
              if($keys>0){
                $wea = file_get_contents('http://www.weather.com.cn/data/sk/'.$keys.'.html');
                $wea = json_decode($wea);
                $wea = $wea->weatherinfo;
                $strword = $wea->city. '当前温度:'.$wea->temp.','. $wea->WD . $wea->WS.'发布时间:'.$wea->time;
              }else{
                $strword = $weather_keyword . '的天气查询不到Ya';
              }
            }
          }
      

  2.   

    针对每个ID创建文件这个开销是不是太大了,关键这个文件不知道什么时候删,又不是跟session文件一样系统会自己处理
      

  3.   

    可以把寫文件的步驟寫入memcache,然後設置超時時間。
      

  4.   

    沒有memcache 就自己生成一個緩存文件 每天晚上0點 清空.