Top Banner
The use of Symfony2 @ Overblog By Xavier HAUSHERR and Gérald Lonlas
36

The use of Symfony2 @ Overblog

Jan 29, 2018

Download

Technology

Xavier Hausherr
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 2: The use of Symfony2 @ Overblog

About Us

Xavier HAUSHERRCTO

Twitter: @xkobal

Gerald LONLASProject manager

Twitter: @geraldlonlas

Page 3: The use of Symfony2 @ Overblog

What is OverBlog?

It’s also:2 millions blogs in 5 languages35 millions uniques visitors per month250 millions pages views per month13th French site audience50 servers to serve blogs

Born in 2004, OverBlog is the top leading European blogging platform.

Was the first platform to share the revenue generated by the audience.

Page 4: The use of Symfony2 @ Overblog

OverBlog before Symfony 2

The previous version of OverBlog is based on:Jelix framework 1.1 CustomPHP 5.2Postgresql 8

Spread on 50 servers:1 database master 11 databases slaves38 hits and caches

Page 5: The use of Symfony2 @ Overblog

OverBlog technical specifications

Capable of handling the loadBe scalableSeparate services: may be switch offReducing the pages execution timeSpeed up data accessStop with the monolithTest driven developmentTake pleasure to develop

Page 6: The use of Symfony2 @ Overblog

PHP Frameworks

Jelix 1.3: Small communityProduct continuity

Zend framework 1: Not full stackNot a framework

Symfony 1: End of lifenot enough modularperformances

Page 7: The use of Symfony2 @ Overblog

Full stack frameworkDependency injectionGood performancesTwig & I18NSymfony communitySensio supportTeam experience in Symfony 1

Why Symfony 2?

Young frameworkToo few bundlesStrongly coupled with DoctrineTime/cost to learn

Page 9: The use of Symfony2 @ Overblog

Projects Distribution

One Symfony project for each part of the platform.Each project must be independent and could be in any language

Portal

Administra-on

Users00(SSO)

Comments Core

Developer0Center Sta-s-cs

Page 10: The use of Symfony2 @ Overblog

Software Used

Page 11: The use of Symfony2 @ Overblog

Projects Distribution

Page 12: The use of Symfony2 @ Overblog

Service Architecture

Databases

Project API

Front End Web

www InternalAPI

Page 14: The use of Symfony2 @ Overblog

First Try: JSON-RPC

Easy to codeREST is natively integrated into Symfony

Object must be rebuilt from JSONNo type validationNo standardNo data model

Poor performance

Page 15: The use of Symfony2 @ Overblog

Some statistics about Web Services

http://jnb.ociweb.com/jnb/jnbJun2009.html

Thrif - TCompactProtocolThrift - TBinaryProtocol

Protocol BuffersRemote Method Invocation (RMI)

REST - JSONREST - XML

0 100 200 300 400 500 600 700 800 900 1000

Size (bytes)

Thrif - TCompactProtocolThrift - TBinaryProtocol

Protocol BuffersRemote Method Invocation (RMI)

REST - JSONREST - XML

0 50 100 150 200 250 300 350 400

Average Wall Time for 10000 queries (s)

Page 16: The use of Symfony2 @ Overblog

Second Try: Apache ThriftDeveloped by FacebookIncubated by Apache Software Foundation

Object data modelDefinition are compiled into classes and interfacesCross languageBasic type validationBinary transferPHP extension

No Symfony integrationObsolete PHP LibrarySmall community

Page 17: The use of Symfony2 @ Overblog

Client

Thrift Bundle

Service client

Controler

write () / read ()

TProtocol

TTransport

Input / output

Server

Service client

Business Service

write () / read ()

TProtocol

TTransport

Input / output

}}

Gen

erat

ed c

ode

Thrift Integration In Symfony

1. Thrift forkGive compatibility with

UniversalClassLoaderReal namespace usageRemove hardcoded inclusion

2. We create a bundle to integrate Thrift into Symfony

Dependency injection integrationDefinitions are compiled at cache warmup

in cache directoryAutoloader or Factory to instantiate object2 modes: HTTP Controller or Socket

daemonUnit Tests

3. Work with developers to integrate these modifications into the next Thrift release.

Page 18: The use of Symfony2 @ Overblog

Thrift Definitionnamespace php ThriftModel.Usernamespace java com.overblog.thriftModel.user

include "Generic/Image.thrift"

exception InvalidValueException{ 1: i32 code, 2: string message}

enum Lang{ FR, EN}

struct User{ 1: i64 id, 2: string email, 3: optional string password, 4: optional Image avatar}

service UserService{ User getUserById(1: i64 id) throws (1: InvalidValueException e), bool deleteUser(1: i64 id) throws (1: InvalidValueException e)}

Page 19: The use of Symfony2 @ Overblog

Thrift Integration In Symfonyservices: overblog_api.extension.user: class: OverblogUser\InternalApiBundle\Api\UserExtension arguments: [@service_container] tags: -: { name: "thrift.extension" }

overblog_thrift: services: user: definition: User namespace: ThriftModel\User bundleNameIn: OverblogCommonBundle server: true

servers: user: service: user handler: overblog_api.extension.user clients: comment: service: user type: http hosts: comment: host: 192.168.0.1 port: 8080

Page 20: The use of Symfony2 @ Overblog

Thrift Integration In Symfonynamespace OverblogUser\InternalApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UserController extends Controller{ public function getUserAction($id) { try { $p = $this->get('thrift.client.user') ->getClient() ->getUserById($id); } catch (\Exception $e) { throw $this->createNotFoundException(); } }}

Page 21: The use of Symfony2 @ Overblog

Thrift Integration In Symfonynamespace OverblogUser\InternalApiBundle\Api;

use ThriftModel\User\UserIf;use Overblog\ThriftBundle\Api\Extensions\BaseExtension;

class UserExtension extends BaseExtension implements UserIf{ public function getUserById($id) { return $this->getInstance( 'ThriftModel\User\User', array( 'id' => $id, 'email' => '[email protected]', 'lang' => ThriftModel\User\Lang::FR ) ); }}

Page 23: The use of Symfony2 @ Overblog

Why a SSO ?

Need only one authentication for several services:

•Administration, •Comments, •Portal•Public API (Mobile app)

Session must be checked in PHP or JavascriptScalability.Must be able to kill a sessionCan be plugged with other system

Page 24: The use of Symfony2 @ Overblog

SSO with Security Bundle

Use the Symfony Security LayerOne provider per serviceBundle creation to secure servicesMain entry point is located on SSOLogout disconnect from project and SSOToken definition with rights embeddedUse RememberMe functionality to have long authenticationCatch security exception to return 401 instead of redirect

Page 25: The use of Symfony2 @ Overblog

User

SSO Diagram

1. User hit a protected ressource

2. User is redirected to SSO

3. User is prompted to log in

4. SSO notifies the server that access has been granted by redirecting user with token

5. User can now access the ressource

Page 27: The use of Symfony2 @ Overblog

Blog rendering

Functional specifications:Allow the fully customization of themesFriendly meta language

Sandbox the theme executionCache pagesGood performance

Page 28: The use of Symfony2 @ Overblog

Why Twig?

The markupAllow sandboxing & policiesMaking our own filtersCompiling theme markupPacked with Symfony 2

Page 29: The use of Symfony2 @ Overblog

Twig usage

Twig_loader_stringNo cache

Twig_loader_stringWith cache

Page 30: The use of Symfony2 @ Overblog

Sandbox configuration# Twig sandbox policy parameters sandbox_policy.tags: [if,list] sandbox_policy.filters: [capitalize, date, default, upper, lower] sandbox_policy.function: [Custom] sandbox_policy.properties: {} sandbox_policy.methods: Overblog\ThemeServiceBundle\Model\BlogInterface: - getTitle - getUrl

# Init Sandbox parameterstwig.extension.sandbox.policy: class: Twig_Sandbox_SecurityPolicy arguments: [ %sandbox_policy.tags%, %sandbox_policy.filters%, %sandbox_policy.methods%, %sandbox_policy.properties%, %sandbox_policy.function% ]

# Enable Twig Sandbox extensiontwig.extension.sandbox: class: Twig_Extension_Sandbox arguments: [@twig.extension.sandbox.policy, false]

Page 31: The use of Symfony2 @ Overblog

Evaluate Twig markup

$source = '<html>.....</html>';

require_once '/path/to/lib/Twig/Autoloader.php';Twig_Autoloader::register();

$loader = new Twig_Loader_String();$twig = new Twig_Environment($loader, array( 'cache' => false,));

$sandboxExtension = new Twig_Extension_Sandbox();$sandboxExtension->enableSandbox();$twig->addExtension($sandboxExtension);

try{ // Evaluate theme with Twig Sandbox $twig->loadTemplate($source)->render( $this->getMockParams() );}catch (Twig_Sandbox_SecurityError $e){ throw new \Exception('Syntax not allowed');}

Page 33: The use of Symfony2 @ Overblog

Internationalization

OverBlog is ported in 5 languagesEnglish, French, Spanish, Italian, German

Our best comboXLIFF format.Pootle opensource tool

Page 34: The use of Symfony2 @ Overblog

XLIFF markup

<trans-unit id="january" approved="yes"> <source>january</source> <target state="translated">January</target></trans-unit>

XLIFF generated by Pootle

Page 35: The use of Symfony2 @ Overblog

Thanks for your time

Questions?

Take some time to create your blog on en.over-blog.com