caxy / appengine-bridge
组件,用于支持在Google App Engine上使用Symfony组件
dev-master / 1.0.x-dev
2015-04-19 21:33 UTC
This package is auto-updated.
Last update: 2024-09-22 06:42:21 UTC
README
此包支持在Google App Engine上使用Symfony及其相关组件。
特性
- 专为App Engine的简单
syslog()
功能设计的Monolog处理器。 - Pimple服务提供者,用于在App Engine上运行Silex。
- 抽象内核基类,为App Engine设置缓存和日志目录。
- 本README。
安装
添加到composer.json
{ "repositories": [ { "type": "vcs", "url": "https://github.com/caxy/AppEngineBridge.git" } ], "require": { "caxy/appengine-bridge": "~1.0@dev" } }
Silex
在其他提供者注册后注册AppEngineProvider
。
<?php $app->register(new \Caxy\AppEngine\Bridge\Pimple\Provider\AppEngineProvider());
请确保在app.yaml
中设置了php55
运行时,否则Silex将失败,因为tempnam()
支持仅在php55
中存在。
Symfony
使用Google App Engine配置文件app.yaml
设置环境变量。使用php55
运行时是必需的。SYMFONY__APP_ENGINE__DEFAULT_BUCKET_NAME
值成为容器参数,并用于设置缓存和日志目录。以下是一个正在进行的示例
application: SOMETHING version: 1 runtime: php55 api_version: 1 threadsafe: true handlers: - url: /bundles static_dir: web/bundles - url: .* script: web/app.php skip_files: - ^(.*/)?#.*#$ - ^(.*/)?.*~$ - ^(.*/)?.*\.py[co]$ - ^(.*/)?.*/RCS/.*$ - ^(.*/)?\..*$ - ^(.*/)?.*/Tests/.*$ - var/cache/* - var/logs/* env_variables: SYMFONY_ENV: prod SYMFONY_DEBUG: 0 SYMFONY__APP_ENGINE__DEFAULT_BUCKET_NAME: 'SOMETHING.appspot.com'
完全替换您的入口控制器,这样您就可以使用app.yaml
环境变量在环境之间切换。这里的示例是Symfony框架标准版的app.php
和app_dev.php
的组合。
<?php use Symfony\Component\ClassLoader\ApcClassLoader; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Debug\Debug; $loader = require_once __DIR__.'/../var/bootstrap.php.cache'; if ((bool) $_SERVER['SYMFONY_DEBUG']) { Debug::enable(); } // Enable APC for autoloading to improve performance. // You should change the ApcClassLoader first argument to a unique prefix // in order to prevent cache key conflicts with other applications // also using APC. /* $apcLoader = new ApcClassLoader(sha1(__FILE__), $loader); $loader->unregister(); $apcLoader->register(true); */ require_once __DIR__.'/../app/AppKernel.php'; //require_once __DIR__.'/../app/AppCache.php'; $kernel = new AppKernel($_SERVER['SYMFONY_ENV'], (bool) $_SERVER['SYMFONY_DEBUG']); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter //Request::enableHttpMethodParameterOverride(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
替换您的AppKernel
扩展的Kernel。
diff --git a/app/AppKernel.php b/app/AppKernel.php index 7673684..0d03d5a 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -1,6 +1,6 @@ <?php -use Symfony\Component\HttpKernel\Kernel; +use Caxy\AppEngine\Bridge\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel
建立memcache
会话处理器。在app/config/services.yml
services: session.memcache: class: Memcache session.handler.memcache: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler arguments: [ @session.memcache ]
Symfony分析器也可以将数据存储在Memcached中。此DSN的具体主机和端口并不重要,因为GAE提供了自己的PHP Memcache
对象。
framework: profiler: dsn: 'memcache://localhost:11211'
使用syslog
Monolog处理器。ident
值并不重要,但对于Symfony实例化处理器是必需的
monolog: handlers: main: type: fingers_crossed action_level: debug handler: syslog syslog: type: syslog ident: whatever
待办事项
- 在GAE上轻松清除Symfony缓存。
- 在更新之前构建不带开发者依赖的应用程序。
其他小优点
在您的composer.json
中添加一个新的scripts
条目,这样您就可以从composer轻松部署。
{ "scripts": { "appengine-update": [ "appcfg.py update . --oauth2" ] } }
现在您可以使用命令composer appengine-update
进行部署。可以将额外的命令堆叠在一起。
{ "scripts": { "appengine-update": [ "composer dumpautoload -o", "appcfg.py update . --oauth2" ] } }