Zend Server: Not just a PHP stack

Post on 28-Jun-2015

700 views 2 download

Tags:

description

There are a lot of tools available that can make developers life easier. Zend Server is one of them. The Zend products have come from a long way, but since the introduction of Zend Server the focus is more on a developers perspective than ever. The integrated tools make debugging, performance tuning, process offloading and deployment really accessible. Even extending it with your own needs is possible nowadays. The current PHP ecosystem gives every developer enormous amounts of power in creating applications without writing a lot of code. In this talk I will show you how Zend Server can help you understand your own PHP application better, by using its tools to open the blackbox that your PHP application really is. This talk is not about selling Zend Server, but helping developers understand why reconsidering your development stack is always an option. Because in the end every developer likes to be a lazy developer.

Transcript of Zend Server: Not just a PHP stack

ZEND SERVER: NOT JUST A PHP STACK

JEROEN VAN DIJK

@JRVANDIJK

BOARD MEMBER

NETHERLANDS

UNITED KINGDOM

BELGIUM

GERMANY

AMSTERDAM

NETHERLANDS

UNITED KINGDOM

BELGIUM

GERMANY

AMSTERDAM

NOT AMSTERDAM

NETHERLANDS

UNITED KINGDOM

BELGIUM

GERMANY

AMERSFOORT

ENRISE HEADQUARTERS

SERVING PHP APPS

WHO’S DOING MANUAL COMPILE OF PHP?

WHO’S USING STOCK DISTRO VERSIONS?

IN PRODUCTION?

WHO’S USING OTHER STACKS?

WRITING YOUR OWN CODE

COMPOSING JSON FILES

GUZZLE

TWIG

MONOLOG

SWIFTMAILER

DOCTRINE

PHPUNIT

ROUTING

YAML

CODECEPTION

EVENTMANAGER

SHIP & DEPLOY

MONITORING

<?php require_once __DIR__ . '/../vendor/autoload.php';

$app = new Silex\Application();

$app->get('/slowrequest', function() use($app) { sleep(5);

return $app->json(array('That was slow')); });

$app->run();

SIMPLE SILEX EXAMPLE

TRIGGERED EVENTS

BASIC CONFIG

THRESHOLD CONFIG

$app = new Silex\Application();

$app->get('/slowrequest', function() use($app) { if (function_exists('zend_monitor_custom_event')) { zend_monitor_custom_event( 'Internal Application Error', 'your error message', array( 'trace' => 'this went wrong' ) ); }

return $app->json(array('That was slow')); });

LOGGING A CUSTOM EVENT

1

ALTERNATIVE: NEW RELIC

CODETRACING & PROFILING

DETAILED INSPECTION

MY PREFERRED METHOD

WARNING!

ENABLED FOR LIMITED TIME

MAXIMUM CODETRACING FILE SIZE

GREAT POWER == GREAT RESPONSIBILITY

2

ALTERNATIVE: XHPROF

DEBUGGING

VAR_DUMP DRIVEN DEVELOPMENT

VDD

VAR_DUMP DRIVEN DEVELOPMENT

VDD

DEBUGGER COMMUNICATION

& DEBUG_PORT=10137 & DEBUG_HOST=172.17.0.199,127.0.0.1

LOCALHOST:20080

DEBUGGER CONFIG

§ Chrome zDebug extension

§ Jetbrains bookmarklets § https://www.jetbrains.com/phpstorm/marklets/

§ Zend debugger toolbar

ENABLE BROWSER DEBUGGING

DEBUG SESSION

DEBUG LOGGED EVENT

REMOTE DEBUGGING

SSH -L <USER> -R 10137:LOCALHOST:10137 <HOST>

3

ALTERNATIVE: XDEBUG

Z-RAY

§ WordPress debug bar

§ Zend Framework 2 developer tools

§ Symfony 2 web profiler

§ Yii debug toolbar

§ ….

§ ….

DEBUG TOOLBARS

§ WordPress debug bar

§ Zend Framework 2 developer tools

§ Symfony 2 web profiler

§ Yii debug toolbar

§ ….

§ ….

DEBUG TOOLBARS

Z-RAY TOOLBAR

Z-RAY TOOLBAR

Z-RAY TOOLS IN ADMIN

Z-RAY TOOLS IN ADMIN

4

ALTERNATIVE: ???

ONE MORE THING

THE EASY WAY

QUEUEING

$app->get('/slowrequest', function() use($app) { $queue = new ZendJobQueue(); $queue->createHttpJob('/sendemail', array( 'email'=>'jeroen@enrise.com'), array('name'=>'Send email') ); return $app->json(array('That wasn\'t slow')); });

$app->post('/sendemail', function() use ($app) { sleep(5); $params = ZendJobQueue::getCurrentJobParams(); ZendJobQueue::setCurrentJobStatus(ZendJobQueue::OK); $response = new Response(); $response->headers->set('X-Info', 'mail send to '. $params['email']); return $response; });

MOVE SLOW REQUEST INTO JOB

/** * See Matthew Weier O'Phinney his blog serie about * Zend Server * * https://mwop.net/blog/2014-09-04-zend-server-deployment- * part-4.html */ if (! ZendJobQueue::getCurrentJobId()) { header('HTTP/1.1 403 Forbidden'); exit(1); }

SECURING JOB ACTIONS

SCHEDULE A JOB

$queue = new ZendJobQueue(); // send the as soon as possible $queue->createHttpJob('/sendemail', array('email'=>'jeroen@enrise.com'), array( 'name'=>'Send email', 'priority' => ZendJobQueue::PRIORITY_URGENT ) );

AS SOON AS POSSIBLE

$queue = new ZendJobQueue(); // send the email tomorrow 2am $queue->createHttpJob('/sendemail', array('email'=>'jeroen@enrise.com'), array( 'name'=>'Send email', 'schedule_time' => date('Y-m-d h:i:s', strtotime('tomorrow 2am')) ) );

AT A SPECIFIC TIME

$queue = new ZendJobQueue(); // send the email every Monday at 2am $queue->createHttpJob('/sendemail', array('email'=>'jeroen@enrise.com'), array( 'name'=>'Send email', 'schedule' => '0 2 * * 1' ) );

RECURRING

MANY MORE THINGS

JAVA BRIDGE

LIBRARIES

OPCODE CACHING

CLUSTERING

APPLICATIONS

PAGE CACHING

WEB API

VIRTUAL HOSTS

CONTINUOUS DELIVERY

DATA CACHING

JOIND.IN/12081