2017-01-10 6 views
0

PHP (runtime: php55)アプリのローカルGoogle Cloud App Engineエミュレータを実行しています。これは、PHPセッションを除いて動作します。私は、次のメッセージが表示されます:GAE gcloud dev_appserver.py PHP:セッションデータの読み込みに失敗しました(パス:Memcache)

Warning: session_start(): Failed to read session data: user (path: Memcache) 

私は、次のコマンド

dev_appserver.py --php_executable_path=/usr/bin/php-cgi ./default 

でアプリを起動だから私は、PHP-CGIを使用して実行します。これの前に、私は通常のPHPで動作しようとしましたが、WSODを取得しました。 Googleグループでは、その問題を解決するphp-cgiを使用することを提案しました。しかし、今私はまだMemcacheに関連しているように見えるこの問題があります。

これはLinux Mint(Ubuntu)にあり、この問題は、エミュレータで同じアプリケーションを実行しているWindowsマシンでは発生しませんでした。

私はphp-memcacheをインストールすると、もうアプリケーションを起動できません。 php-memcacheをインストールした状態で上記のコマンドを実行すると、次のエラーが表示されます。

PHPEnvironmentError: The PHP runtime cannot be run with the 
"Memcache" PECL extension installed 

どうすれば解決できますか?

答えて

0

私はPHP cgiの問題を解決しませんでしたが、私は自分のセッションハンドラを作成することでその問題を解決しました。 GAEはデフォルトでMemcacheにセッションを 'user'セッションハンドラとともに保存します。それが何らかの理由で動作しない場合は、次のコードを使用してローカルGAEを 'ファイル'セッションハンドラに切り替えて、セッションをフォルダに保存することができます:

<?php 

if ($_SERVER['SERVER_NAME'] == 'localhost') { 

    class FileSessionHandler { 

     private $savePath; 

     function open($savePath, $sessionName) { 
      $this->savePath = $savePath; 
      if (!is_dir($this->savePath)) { 
       mkdir($this->savePath, 0777); 
      } 

      return true; 
     } 

     function close() { 
      return true; 
     } 

     function read($id) { 
      return (string) @file_get_contents("$this->savePath/sess_$id"); 
     } 

     function write($id, $data) { 
      return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true; 
     } 

     function destroy($id) { 
      $file = "$this->savePath/sess_$id"; 
      if (file_exists($file)) { 
       unlink($file); 
      } 

      return true; 
     } 

     function gc($maxlifetime) { 
      foreach (glob("$this->savePath/sess_*") as $file) { 
       if (filemtime($file) + $maxlifetime < time() && file_exists($file)) { 
        unlink($file); 
       } 
      } 

      return true; 
     } 

    } 

    $handler = new FileSessionHandler(); 
    session_set_save_handler(
      array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc') 
    ); 
    session_save_path('[PATH_TO_WRITABLE_DIRECTORY]'); 

    register_shutdown_function('session_write_close'); 
} 

session_start(); 
関連する問題