Download presentation
Presentation is loading. Please wait.
Published byMarjorie West Modified over 9 years ago
1
PHP + Erlang ускоряем checkout
2
Checkout – оформление заказа Screenshot Onepage checkout server Ajax request Next step HTML Database
3
Erlang – язык программирования Функциональный Старый (1987 год), но до сих пор активно развивающийся (последний релиз – апрель 2012) Создавать много легковесных процессов Транслируется в байт-код и запускается виртуальной машиной
4
Многопоточность PHP и так для каждого HTTP запроса создает новый поток Чрезмерная многопоточность усложняет программу Хотя, кое где многопоточность нужна
5
Демонизация PHP load save Request 1 Response 1 load save Request 2 Response 2 load save Request 3 Response 3 Process #1 Process #2 Process #3 Web (PHP) application load save Request 1 Request 2 Request 3 Response 1 Response 2 Response 3 Process #1 Daemon
6
Инфраструктура Front script Erlang manager PHP node 1.Упаковывает Request 2.Отсылает его в Erlang Manager 3.Получает и распаковывает Response Создает новый или передает управление в существующий процесс Неподходящие запросы выполняются как обычно 1.Распаковывает Request 2.Обрабатывает его 3.Упаковывает и отсылает обратно Response Magento user 1 user 2user 3 user 4 user 5 user 1 user 2user 3 user 4user 5
7
Пример кода front script <?php if (isCheckoutRequest()) { runParallel(); } else { runMagento(); } function runParallel() { $parallel = new Mage_Parallel( array('host' => '127.0.0.1', 'port' => '7000', 'secret_cookie' => 'Secret‘) ); $env = array('server' => $_SERVER, 'get' => $_GET, 'post' => $_POST, ‘cookie' => $_COOKIE); $result = unserialize($parallel->call('runApp', array($env), $_COOKIE[‘frontend’])); $response = new Zend_Controller_Response_Http(); $response->setBody($result['body'])->setHttpResponseCode($result['responseCode']); foreach ($result['headers'] as $header) { $response->setHeader($header['name'], $header['value'], $header['replace']); } $response->sendResponse(); }
8
Пример кода PHP node <?php include_once '../../../../../../app/Mage.php'; $isMageRun = false; function runApp($env) { $_SERVER = $env['server']; $_GET = $env['get']; $_POST = $env['post']; $_COOKIE = $env['cookie']; ob_start(); if (!$isMageRun) { Mage::run(); $isMageRun = true; } else { preapreApp(); /* clean some singletons and objects*/ Mage::app()->setRequest(new Mage_Core_Controller_Request_Http()); Mage::registry('controller')->dispatch(); } ob_get_clean(); return serialize(array( 'body' => Mage::app()->getResponse()->getBody(), 'headers' => Mage::app()->getResponse()->getHeaders(), 'responseCode' => Mage::app()->getResponse()->getHttpResponseCode() )); }
9
Как работает checkout load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote create and save order load Quote collect totals save Quote create and save order MySQL database MySQL database Checkout steps Quote process step 1 step 2 step 3 step 4
10
load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote load Quote collect totals save Quote create and save order load Quote collect totals save Quote create and save order MySQL database MySQL database Quote process Checkout steps step 1 step 2 step 3 step 4 Как работает checkout
11
Ресурсы PHP eval сервер для erlang - https://github.com/skeltoac/php_app PHP расширение для запуска Php, как erlang cnode - https://code.google.com/p/mypeb
12
Q&AQ&A Руслан Грабовой rgrabovoy@ebay.com Саша Кусакин akusakin@ebay.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.