我有一個託管在AWS Elastic Beanstalk上的CakePHP應用程序。由於將來會使用多個EC2實例,我想將我的PHP會話存儲在數據庫中。 AWS提供了一個非常好的庫,用於在其DynamoDB數據庫中存儲PHP會話。見http://goo.gl/URoi3sCakePHP:使用AWS的DynamoDB會話處理程序
現在我的推杆AWS的SDK在我的文件夾的供應商,創造了一個訪問包裝它(插件):
<?php
Configure::load('aws');
require_once VENDORS . 'autoload.php';
use Aws\Common\Aws;
class AwsComponent extends Component
{
private $_aws;
public function __construct()
{
$this->_aws = Aws::factory(array(
'key' => Configure::read('Aws.key'),
'secret' => Configure::read('Aws.secret'),
'region' => Configure::read('Aws.region')
));
}
public function getClient($service)
{
return $this->_aws->get($service);
}
}
的包裝運作良好,我已經實現了一些東西S3。現在的會話處理程序添加以下代碼到我的AppController.php:
public $components = array('Aws.Aws');
public function beforeFilter()
{
$this->_setSessionStorage();
}
private function _setSessionStorage()
{
$client = $this->Aws->getClient('dynamodb');
$client->registerSessionHandler(array(
'table_name' => 'sessions'
));
}
的AWS的內部registerSessionHandler()被執行(測試過),但會議沒有beeing存儲到DynamoDB表。當然,我之前創建了表,如果在調度程序加載之前將調用直接添加到我的webroot/index.php,則一切正常。
我認爲問題在於我的代碼在CakePHP調用session_start()後執行。那麼實現它的最好方法是什麼? http://goo.gl/kUFUIR不能幫助我,我不想重寫AWS庫以便與CakePHP接口兼容。
好,謝謝,如果是我會試試看的唯一途徑。 – iscon