承接 caxy/appengine-bridge 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

caxy/appengine-bridge

Composer 安装命令:

composer require caxy/appengine-bridge

包简介

Components to support Symfony components in Google App Engine

README 文档

README

This package supports Symfony and related components on Google App Engine.

Features

  • Monolog handler specifically for App Engine's simple syslog() facility.
  • Pimple service provider for running Silex on App Engine.
  • Abstract kernel base class that sets cache and log directories for App Engine.
  • This README.

Installation

Add to composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/caxy/AppEngineBridge.git"
        }
    ],
    "require": {
        "caxy/appengine-bridge": "~1.0@dev"
    }
}

Silex

Register the AppEngineProvider after your other providers have been registered.

<?php
$app->register(new \Caxy\AppEngine\Bridge\Pimple\Provider\AppEngineProvider());

Make sure that the php55 runtime is set in your app.yaml or else Silex will fail because tempnam() support is only in php55.

Symfony

Use the Google App Engine configuration file app.yaml to set environment variables. Using the php55 runtime is required. The SYMFONY__APP_ENGINE__DEFAULT_BUCKET_NAME value becomes a container parameter and is used to set up cache and log directories. Here is a work-in-progress example:

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'

Replace your front controller entirely so you can switch between environments using the app.yaml environment variable. The example here is a combination of Symfony framework Standard Edition's app.php and 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);

Replace the Kernel that your AppKernel extends.

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

Establish memcache session handler. In app/config/services.yml:

services:
    session.memcache:
        class: Memcache

    session.handler.memcache:
        class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
        arguments: [ @session.memcache ]

The Symfony profiler can store data in Memcached too. The specific host and port of this DSN are not important as GAE supplies its own PHP Memcache object.

framework:
    profiler:
        dsn: 'memcache://localhost:11211'

Use the syslog Monolog handler. The ident value is unimportant but required for Symfony to instantiate the handler:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: debug
            handler:      syslog
        syslog:
            type: syslog
            ident: whatever

Features to do

  • Easily purge Symfony cache on GAE.
  • Build the application without developer dependencies prior to updating.

Other Niceties

In your composer.json add a new scripts entry so that you can deploy easily from composer.

{
    "scripts": {
        "appengine-update": [
             "appcfg.py update . --oauth2"
        ]
    }
}

Now you can deploy with the command composer appengine-update. Additional commands can be stacked together.

{
    "scripts": {
        "appengine-update": [
             "composer dumpautoload -o",
             "appcfg.py update . --oauth2"
        ]
    }
}

caxy/appengine-bridge 适用场景与选型建议

caxy/appengine-bridge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 caxy/appengine-bridge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 caxy/appengine-bridge 我们能提供哪些服务?
定制开发 / 二次开发

基于 caxy/appengine-bridge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 33
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-30