2010-12-12 20 views
0

私はResinを使用してGAEを開発しています。本番サイトでの私のPHPセッションは短期間であり、更新されていないようです(リクエストを作成すると期限切れにはならないようです期間)。ローカルは問題ありません。私がタブを閉じない限り、セッションは継続します。Google App EngineのResinセッション

これに関するポインターはありますか?彼らは非常に頻繁に蹴られて私のユーザーが不満を取得している:(

+0

「リモートサイト」とは何ですか? App Engineを使用して、別の別のサイトにリクエストしていますか? –

+0

申し訳ありませんが、私は生産サイト、更新 –

答えて

1

を私はコードが最高のチュートリアルだと思います:)

あなたがセットに追加し、メソッドまたはより良いを取得する必要があり、適切なセッション機能のための今すぐ
// global mem cache service handle 
$MEM_CACHE_SERVICE = NULL; 
// table to store session like information 
$MY_SESSION_TABLE = array(); 

function load_mcache($key) { 
    global $MEM_CACHE_SERVICE; 
    if (!$MEM_CACHE_SERVICE) { 
     import com.google.appengine.api.memcache.MemcacheServiceFactory; 
     import com.google.appengine.api.memcache.Expiration; 
     $MEM_CACHE_SERVICE = MemcacheServiceFactory::getMemcacheService(); 
    } 
    return $MEM_CACHE_SERVICE->get($key); 
} 

function save_mcache($key, $value, $cache_time) { 
    global $MEM_CACHE_SERVICE; 
    if (!$MEM_CACHE_SERVICE) { 
     import com.google.appengine.api.memcache.MemcacheServiceFactory; 
     import com.google.appengine.api.memcache.Expiration; 
     $MEM_CACHE_SERVICE = MemcacheServiceFactory::getMemcacheService(); 
    } 
    $expiration = Expiration::byDeltaSeconds($cache_time); 
    return $MEM_CACHE_SERVICE->put($key, $value, $expiration); 
} 

// unserializing array from mem cache 
// if nothing found like first time and after a minute, then add key to the table 
if (!($MY_SESSION_TABLE = unserialize(load_mcache($_REQUEST['JSESSIONID'])))) { 
    // save something to cache on first page load because we didnt have anything 
    $MY_SESSION_TABLE['key1'] = date('m/d/Y H:i:s'); 
    // using jsessionid as a mem cache key, serializing array and setting cache time to one minute 
    save_mcache($_REQUEST['JSESSIONID'], serialize($MY_SESSION_TABLE), 60); 
} 

// now my session table is available for a minute until its initialized again 
print_r($MY_SESSION_TABLE); 

それを処理するための小さなクラスです。クラスへの抽象化がほとんどなく、異なるWebアプリケーションシナリオで同じライブラリでどのようなセッションメカニズムを使用するかを選択できます。