Upload
vadim-borodavko
View
6.233
Download
2
Embed Size (px)
DESCRIPTION
- HipHop – replacement for Zend PHP - HPHPc and HHVM - Supported OS - Compatibility with PHP: version, extensions - Operational modes: CLI, Server - Configuration features - Performance: capital.ua on Symfony 1.4, Sylius on Symfony 2.3 - HHVM with your project: Vagrant - Popular frameworks and CMS support - Competitors: kPHP
Citation preview
HipHop – replacement for Zend PHP
Vadim Borodavko
© 2008 – 2013
HipHop – replacement for Zend PHP
0
10
20
30
40
50
60
70
80
90
01.02.2010
01.04.2010
01.06.2010
01.08.2010
01.10.2010
01.12.2010
01.02.2011
01.04.2011
01.06.2011
01.08.2011
01.10.2011
01.12.2011
01.02.2012
01.04.2012
01.06.2012
01.08.2012
01.10.2012
01.12.2012
01.02.2013
01.04.2013
01.06.2013
01.08.2013
01.10.2013
Contributors
Vadim Borodavko
Two ways
HPHPc
• Up to 6x faster than Zend PHP 5.2
• No source code in production
Vadim Borodavko
Two ways
HPHPc
• Compilation takes long time
• Big executable files
• Dynamic code
Vadim Borodavko
Two ways
HHVM
• JIT-compilation
• Dynamic code
• Edit – Save – Run
Vadim Borodavko
Two ways
HHVM
• The need for revision of the existing
PHP-code
Vadim Borodavko
Supported OS
Ubuntu
Vadim Borodavko
Mint Debian Fedora
CentOS Arch Gentoo
Mac OS FreeBSD
Supported OS
Vadim Borodavko
https://github.com/javer/gentoo-overlay
Compatibility with PHP
5.4.999-hiphop
Vadim Borodavko
PHP 5.5 – to the end of 2013 year
Compatibility with PHP
5.3 features
• namespaces
• late static binding
• goto
• Closures
• ternary operator
Vadim Borodavko
Compatibility with PHP
5.4 features
• traits
• $a = [1, 2, 3, 4];
• foo()[0]
• Closures with $this
• (new Foo)->bar()
Vadim Borodavko
• Class::{expr}()
Compatibility with PHP
5.5 features
• generators
• finally*
• list() in foreach
• empty(expr)
• [1, 2, 3][0]
Vadim Borodavko
• password_hash()
• ClassName::class
• “Hello”[0]
Compatibility with PHP
Extensions
50+
Vadim Borodavko
• fileinfo
• imagick
• intl*
• mysqli
• tidy
• xsl
PHP language extension
<?hh class Walk<T as Iterator> { private T $iterator; public function setIterator(T $iterator, int $count): int { $this->iterator = $iterator; $keys = Vector<int> {}; $values = Map<int, string> {}; foreach ($iterator as $k => $v) { $keys->add($k); $values[$k] = $v; } return count($keys); } } $iter = new ArrayIterator([1 => 'first', 2 => 'second']); echo (new Walk<ArrayIterator>)->setIterator($iter,count($iter));
Vadim Borodavko
PHP language extension
Vadim Borodavko
PHP language extension
Type hinting
Vadim Borodavko
private int $count;
protected string $name;
public function setCount(int $count): int {
$this->iterator = $iterator;
}
PHP language extension
Tuples
Vadim Borodavko
public $t = tuple(“Symfony”, true);
PHP language extension
Collections
Vadim Borodavko
$keys = Vector<int> {};
$values = Map<int, string> {};
$keys->add($k);
$values[$k] = $v;
echo count($keys);
PHP language extension
Generics, Constraints
Vadim Borodavko
class Walk<T as Iterator> { private T $iter; public function setIterator(T $iter) { ... } } new Walk<ArrayIterator>();
Operational modes
• PHP CLI: hhvm --php
• A bit slower than Zend PHP
• JIT-compilation*
CLI
Vadim Borodavko
Operational modes
• Apache
• Compilation at startup
• FastCGI – soon
• RepoAuthoritative mode
Server
Vadim Borodavko
Configuration features
• Eval
• Log
• Server
• VirtualHost
• AdminServer
• StaticFile
config.hdf
• Stats
• MySQL
• Http
• Tiers
Vadim Borodavko
Configuration features
Eval { Jit = true JitWarmupRequests = 11 JitASize = 536870912 # 512MB JitAStubsSize = 536870912 # 512MB JitGlobalDataSize = 134217728 # 128MB }
Eval
Eval { JitASize = 134217728 # 128MB JitAStubsSize = 134217728 # 128MB JitGlobalDataSize = 67108864 # 64MB }
Vadim Borodavko
Configuration features
Server { Host = domain.tld IP = 127.0.0.1 Port = 4247 ThreadCount = 10 SourceRoot = /var/www/domain.tld IncludeSearchPaths { symfony = /var/www/symfony-1.4 } RequestTimeoutSeconds = 30 RequestMemoryMaxBytes = 134217728 }
Server
Vadim Borodavko
Configuration features
Server { DefaultDocument = index.php StartupDocument = filename WarmupDocument = filename RequestInitFunction = function_name ThreadDocuments { * = somedoc.php * = another.php } ErrorDocument404 = 404.php FatalErrorMessage = Something wrong }
Server startup options
Vadim Borodavko
Configuration features
Server { ... GzipCompressionLevel = 3 EnableMagicQuotesGpc = false EnableKeepAlive = true EnableEarlyFlush = true ForceChunkedEncoding = false MaxPostSize = 65 # in MB LibEventSyncSend = true ResponseQueueCount = 0 ... }
Server http settings
Vadim Borodavko
Configuration features
VirtualHost { default { Disabled = false Prefix = prefix. Pattern = .* PathTranslation = web/ ServerName = domain.tld ServerVariables { name = value } RewriteRules { } } }
VirtualHost
Vadim Borodavko
Configuration features
frontend { pattern = ^(.*)$ to = app.php/$1 qsa = true conditions { not_script { pattern = \.php$ type = request negate = true } } }
VirtualHost \ RewriteRules
Vadim Borodavko
Configuration features
AdminServer { Port = 4248 ThreadCount = 1 Password = password } StaticFile { Extensions { bmp = image/bmp } Generators { * = static_resource.php } }
AdminServer, StaticFile
Vadim Borodavko
Configuration features
Stats { Web = false Memory = false APC = false APCKey = false SQL = false } MySQL { ReadOnly = false ConnectTimeout = 1000 ReadTimeout = 4000 SlowQueryThreshold = 2000 KillOnTimeout = false }
Stats, MySQL
Vadim Borodavko
Configuration features
Http { DefaultTimeout = 30 SlowQueryThreshold = 5000 } Mail { SendmailPath = sendmail -t -i ForceExtraParameters = } Tiers { * { machine = /regex pattern/ overwrite { ... } } }
Http, Mail, Tiers
Vadim Borodavko
Configuration features
Vadim Borodavko
Performance: HHVM vs PHP
1.4
URL Time, ms Memory, KB
PHP 5.3 PHP 5.5 HHVM 2.2 PHP 5.3 PHP 5.5 HHVM 2.2
/ 58 49 17 18 668 16 128 615
/politics 57 48 16 18 688 15 872 598
/publication/5
129- 68 54 18 23 808 20 736 607
/publication 56 45 17 18 176 15 360 606
/issue/92 51 40 15 17 408 14 592 617
/app 45 36 13 16 128 13 824 498
/time 56 45 16 18 432 15 616 554
/tag/siriya 61 49 18 18 784 16 032 586
Vadim Borodavko
Performance: HHVM vs PHP
1.4
Vadim Borodavko
0 10 20 30 40 50 60
Time, msHHVM 2.2
PHP 5.5
PHP 5.3
0 5 10 15 20
Memory, MBHHVM 2.2
PHP 5.5
PHP 5.3
Performance: HHVM vs PHP
2.3
URL
Time, ms Memory, KB
PHP 5.3 PHP 5.5 HHVM 2.2 PHP 5.3 PHP 5.5 HHVM 2.2
/ 119 91 67 13 056 10 240 796
/t/t-shirts 139 105 74 15 360 12 032 1 315
/p/t-shirt-
autem 123 94 68 15 616 11 264 662
/cart 106 81 63 13 056 10 240 550
/register/ 109 84 64 14 336 10 752 571
/login 102 78 61 12 288 9 728 549
Vadim Borodavko
Performance: HHVM vs PHP
Vadim Borodavko
0 50 100 150
Time, msHHVM 2.2
PHP 5.5
PHP 5.3
0 5 10 15
Memory, MBHHVM 2.2
PHP 5.5
PHP 5.3
2.3
HHVM with your project
$ git clone https://github.com/javer/hhvm-vagrant-vm
$ cd hhvm-vagrant-vm
$ cp -R /var/www/site/* ./
$ vagrant up
$ wget http://127.0.0.1:9080/
$ wget http://127.0.0.1:9081/
Vagrant
Vadim Borodavko
HHVM with your project
• Symfony
https://github.com/javer/symfony1
• sfPropelORMPlugin
https://github.com/propelorm/sfPropelORMPlugin
• Propel
https://github.com/propelorm/Propel
• Phing 2.6+
https://github.com/phingofficial/phing
1.4
Vadim Borodavko
HHVM with your project
• Doctrine DBAL
• Doctrine 2 ORM
• Twig
• ResourceBundle
2.3
Vadim Borodavko
HHVM with your project
• func_get_args
https://github.com/doctrine/dbal/pull/372
2.3
Vadim Borodavko
Doctrine DBAL
PDOConnection extends PDO implements Connection
PDOStatement extends \PDOStatement implements Statement
• implement declared interfaces
https://github.com/doctrine/dbal/pull/373
HHVM with your project
• func_get_args
https://github.com/doctrine/doctrine2/pull/790
Vadim Borodavko
2.3 Doctrine 2 ORM
• Preserve class property DocComment for reflection https://github.com/facebook/hhvm/pull/1199
HHVM with your project
• Array sometimes can be Traversable
https://github.com/fabpot/Twig/pull/1192
Vadim Borodavko
2.3 Twig
HHVM with your project
• ResourceBundle
https://github.com/javer/hhvm/tree/intl-
resourcebundle/hphp/system/php/intl
Vadim Borodavko
2.3
Popular frameworks and CMS support
Framework % Unit Tests
Pass
% Unit Tests
Failing
% Unit Tests
Causing HHVM
to Fatal
Symfony 2 98.12 1.51 0.37
Doctrine DBAL 97.61 1.39 1.00
Doctrine 2 ORM 99.41 0.59 0
Twig 100 0 0
PHPUnit 90.52 9.48 0
Composer 99.13 0.87 0
Symfony 1.4 97 3 0
HHVM 2.2-dev
Vadim Borodavko
Popular frameworks and CMS support
HHVM 2.1 Framework % Unit Tests Pass % Unit Tests Failing % Unit Tests Causing
HHVM to Fatal
PHPUnit 90 10 0
Composer 97 3 < 1
Symfony 91 9 < 1
CakePHP 0 Tests won't run Tests won't run
Wordpress 76 24 < 1
Joomla 0 Tests won't run Tests won't run
phpBB 0 100 0
phpMyAdmin 0 Tests won't run Tests won't run
Laravel 95 3 2
Zend Framework 2 0 Tests won't run Tests won't run
yii 92 8 < 1
Slim 99 1 0
Doctrine 0 Tests won't run Tests won't run
Assetic 80 20 0
Twig 78 22 0
Drupal 98 2 0
Paris 100 0 0
Idiorm 100 0 0
CodeIgniter 81 19 < 1
Magento 0 Tests won't run Tests won't run
Vadim Borodavko
Competitors
Vadim Borodavko
Competitors
• Translator PHP into C++
• Strict typing
• Vkontakte size – 300 MB
kPHP
Vadim Borodavko
Competitors
does not
support OOP
at all.
© 2013
kPHP
Vadim Borodavko
About me
Vadim Borodavko
• Chief Software Developer at Argentum IT Lab
• E-mail: [email protected]
• GitHub: https://github.com/javer
• LinkedIn: http://linkedin.com/in/javer
• Twitter: https://twitter.com/mrjaver
Vadim Borodavko
All trademarks are property of their respective owners