Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
UNKNOWN FEATURES OF
PHP
or less known ;)
ABOUT ME
CERTIFIED
PHP ENGINEER
CERTIFIED
A R C H I T E CT
2
Łukasz Witczak
10+ yrs experience
STRICTTYPED PHP?
IS IT POSSIBLETO WRITE
STRICTLYTYPED PHP CODE?
Never trust accepted answer at stackoverflow
STATIC/DYNAMIC
STRICT/WEAK?
• Static/Dynamic typing is about when type
information is aquired (at compiletime or at
runtim...
WEAKTYPING AND STRICT
TYPING
• Fully strict type checking where no conversion happens (Go,
Facebook's Hack)
• Widening pri...
“DESPITE THEIR PRODUCTIVITY
ADVANTAGES, DYNAMIC
LANGUAGES MAY NOT BE THE BEST
CHOICES FOR ALL APPLICATIONS,
PARTICULARLY F...
TYPE HINTING PHP 5+
TYPE HINTING PHP7
SCALARTYPE HINTS
FOR PHP 5.4+
• string
• integer, int
• float, double
• boolean, bool
• resource
https://pecl.php.net/packa...
LIMITATIONS
• “Internal functions cannot use strict hints, only user
code is supported.”
• “Because the parser detects sca...
–Joe Watkins
“ I'm super busy right now and this isn't really a
priority ...”
FUTURE
SPL_TYPES
http://php.net/manual/en/intro.spl-types.php
“This extension aims at helping people making PHP a
stronger typed language a...
demo?
SPL_TYPES
• Total downloads: 53,633
ZEPHIR
Zephir, an open source, high-level language designed to ease the
creation and maintainability of extensions for PHP...
ZEPHIR STATICTYPES
• boolean A boolean expresses a truth value. It can be either ‘true’ or ‘false’.
• integer Signed integ...
ZEPHIR UNSIGNED INT
ZEPHIR CHAR AND STRING
ASYNCHRONOUS PHP
cooperative multitasking
SYNCHRONOUS
Tasks
Time
0 150 300 450 600
Task #1 Task #2 Task #3
ASYNCHRONOUS
Tasks
Time [ms]
0 75 150 225 300
Task #1 Task #2 Task #3
NODE.JS
EVENT-DRIVEN, NON-
BLOCKING I/O WITH PHP
pond 3mln pobrań promise
• StreamSelectLoop - out of the box
• LibEventLoop -This uses the libevent pecl extension with a
number of system-specific ...
by Marc J. Schmidt
• http://marcjschmidt.de/blog/2014/02/08/php-
high-performance.html
• https://github.com/php-pm/php-pmLibEvLoop
• http://r...
https://github.com/ratchetphp/Ratchet
ratchetphp/Ratchet
Ratchet is a loosely coupled PHP library providing developers wit...
• Supports the RFC6455, HyBi-10+, and Hixie76 protocol
versions (at the same time)
• Tested on Chrome 13+, Firefox 6+, Saf...
https://github.com/nrk/predis-async
Predis/Async
https://github.com/bixuehujin/reactphp-mysql
react/mysql
• mysql (with non blocking I/O) driver for
reactphp,
• It is written in pure PHP - implemented the
mysql protocol.
react/m...
• Installs: 530
• Stars: 58
• Watchers: 11
• Forks: 13
• Open Issues: 3
react/mysql
https://github.com/reactphp/filesystem
react/filesystem
• Evented filesystem access utilising
asyncronous POSIX I/O by means of
libEIO C library
• requires http://php.net/eio exte...
react/filesystem
• Installs: 1 014
• Dependents: 2
• Stars: 33
• Watchers: 10
• Forks: 7
• Open Issues: 5
filesystem non-blocking I/O
HACK LANG
• Async,Await,Awaitable
HACK LANG
HACK LANG
od hhvm 3.6 - obecnie hhvm 3.10
ASYNC DB QUERIES
ASYNC MYSQL
mysqli::reap_async_query
mysqli_reap_async_query
ASYNC POSTGRESQL
ASYNC HTTP
CURL_MULTI
BUZZ
BUZZMULTI
BUZZVS BUZZMULTI
Time[ms]
0
1250
2500
3750
5000
Sync Multi
Trudność w gromadzeniu requestów
GUZZLE 5
END OF SCRIPT
http://www.rfc-editor.org/rfc/rfc1945.txt 200
http://www.rfc-editor.org/rfc/rfc7540.txt 200
http://...
composer require “guzzlehttp/guzzle:~5.3”
THREADS
YES!
PHP Threads…
…and NOT
pcntl_fork
https://pecl.php.net/package/pthreads
https://github.com/krakjoe/pthreads
http://php.net/pthreads
PTHREADS
• Object Orientated (like Java)
• Easy to use an safety built in (no MUTEX)
• High level implementation of POSIX ...
PTHREADS EXAMPLE
PTHREADS
• Stable since 2013-09-08 (0.0.45)
• Over 163,000 downloads (from PECL)
• Heavily developed: (35 releases)
• Matu...
PTHREADS
• http://pthreads.org/
• https://gist.github.com/krakjoe/9384409
• https://gist.github.com/krakjoe/6437782
read fi...
PTHREADS
Not for web
–Joe Watkins
“(…)you can't use pthreads safely and sensibly
anywhere but CLI.”
PTHREADS
PHP-CLI YES!
THREDS ARE HARD
• https://web.stanford.edu/~ouster/cgi-bin/papers/
threads.pdf
OPERATOR OVERLOADING
OPERATOR OVERLOADING IN PHP
EXTENSIONS
OPERATOR OVERLOADING IN PHP
EXTENSIONS
THANKYOU
https://joind.in/16171
@woocashw
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Unknown features of PHP
Upcoming SlideShare
Loading in …5
×

Unknown features of PHP

435 views

Published on

Uknowns feautres of fphp that can improve your app.

Published in: Internet
  • Be the first to comment

Unknown features of PHP

  1. 1. UNKNOWN FEATURES OF PHP or less known ;)
  2. 2. ABOUT ME CERTIFIED PHP ENGINEER CERTIFIED A R C H I T E CT 2 Łukasz Witczak 10+ yrs experience
  3. 3. STRICTTYPED PHP?
  4. 4. IS IT POSSIBLETO WRITE STRICTLYTYPED PHP CODE? Never trust accepted answer at stackoverflow
  5. 5. STATIC/DYNAMIC STRICT/WEAK? • Static/Dynamic typing is about when type information is aquired (at compiletime or at runtime) • Strong/Weak typing is about how strictly types are distinguished (e.g. whether the language tries to do implicit conversion from strings to numbers).
  6. 6. WEAKTYPING AND STRICT TYPING • Fully strict type checking where no conversion happens (Go, Facebook's Hack) • Widening primitive type checking where “safe” conversions happen (Java, Pascal, PHP Objects). • Weak type checking which all conversions are allowed, with possible warnings raised (which is used to a limited extent by C, C#, C++ andVisual Basic, PHP scalars?)
  7. 7. “DESPITE THEIR PRODUCTIVITY ADVANTAGES, DYNAMIC LANGUAGES MAY NOT BE THE BEST CHOICES FOR ALL APPLICATIONS, PARTICULARLY FOR VERY LARGE CODE BASES AND HIGH- PERFORMANCE APPLICATIONS.” http://docs.zephir-lang.com/en/latest/motivation.html#statically-typed- versus-dynamically-typed-languages
  8. 8. TYPE HINTING PHP 5+
  9. 9. TYPE HINTING PHP7
  10. 10. SCALARTYPE HINTS FOR PHP 5.4+ • string • integer, int • float, double • boolean, bool • resource https://pecl.php.net/package/strict
  11. 11. LIMITATIONS • “Internal functions cannot use strict hints, only user code is supported.” • “Because the parser detects scalar hints as classes, they cannot have default values.” This was written before we knew that PHP7 would get strict parameter and return typing. The best thing to do now is probably make this a close approximation of compatibility for PHP5 ... I'm super busy right now and this isn't really a priority …
  12. 12. –Joe Watkins “ I'm super busy right now and this isn't really a priority ...” FUTURE
  13. 13. SPL_TYPES
  14. 14. http://php.net/manual/en/intro.spl-types.php “This extension aims at helping people making PHP a stronger typed language and can be a good alternative to scalar type hinting.” SPL_TYPES
  15. 15. demo?
  16. 16. SPL_TYPES • Total downloads: 53,633
  17. 17. ZEPHIR Zephir, an open source, high-level language designed to ease the creation and maintainability of extensions for PHP with a focus on type and memory safety.
  18. 18. ZEPHIR STATICTYPES • boolean A boolean expresses a truth value. It can be either ‘true’ or ‘false’. • integer Signed integers.At least 16 bits in size. • unsigned integer Unsigned integers.At least 16 bits in size. • char Smallest addressable unit of the machine that can contain basic character set. • unsigned char Same size as char, but guaranteed to be unsigned. • long Long signed integer type.At least 32 bits in size. • unsigned long Same as long, but unsigned. • float/double Double precision floating-point type.The size is platform-dependent. • string A string is series of characters, where a character is the same as a byte. • array An structure that can be used as hash, map, dictionary, collection, stack, etc.
  19. 19. ZEPHIR UNSIGNED INT
  20. 20. ZEPHIR CHAR AND STRING
  21. 21. ASYNCHRONOUS PHP cooperative multitasking
  22. 22. SYNCHRONOUS Tasks Time 0 150 300 450 600 Task #1 Task #2 Task #3
  23. 23. ASYNCHRONOUS Tasks Time [ms] 0 75 150 225 300 Task #1 Task #2 Task #3
  24. 24. NODE.JS
  25. 25. EVENT-DRIVEN, NON- BLOCKING I/O WITH PHP
  26. 26. pond 3mln pobrań promise
  27. 27. • StreamSelectLoop - out of the box • LibEventLoop -This uses the libevent pecl extension with a number of system-specific backends (epoll, kqueue). • LibEvLoop -This uses the libev pecl extension (github). It supports the same backends as libevent. • ExtEventLoop -This uses the event pecl extension. It supports the same backends as libevent loop
  28. 28. by Marc J. Schmidt
  29. 29. • http://marcjschmidt.de/blog/2014/02/08/php- high-performance.html • https://github.com/php-pm/php-pmLibEvLoop • http://reactphp.org/ • https://github.com/reactphp resources
  30. 30. https://github.com/ratchetphp/Ratchet ratchetphp/Ratchet Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets. http://socketo.me/
  31. 31. • Supports the RFC6455, HyBi-10+, and Hixie76 protocol versions (at the same time) • Tested on Chrome 13+, Firefox 6+, Safari 5+, iOS 4.2+, IE 8+ • Ratchet passes the Autobahn Testsuite (non-binary messages)
  32. 32. https://github.com/nrk/predis-async Predis/Async
  33. 33. https://github.com/bixuehujin/reactphp-mysql react/mysql
  34. 34. • mysql (with non blocking I/O) driver for reactphp, • It is written in pure PHP - implemented the mysql protocol. react/mysql
  35. 35. • Installs: 530 • Stars: 58 • Watchers: 11 • Forks: 13 • Open Issues: 3 react/mysql
  36. 36. https://github.com/reactphp/filesystem react/filesystem
  37. 37. • Evented filesystem access utilising asyncronous POSIX I/O by means of libEIO C library • requires http://php.net/eio extension react/filesystem
  38. 38. react/filesystem
  39. 39. • Installs: 1 014 • Dependents: 2 • Stars: 33 • Watchers: 10 • Forks: 7 • Open Issues: 5 filesystem non-blocking I/O
  40. 40. HACK LANG • Async,Await,Awaitable
  41. 41. HACK LANG
  42. 42. HACK LANG od hhvm 3.6 - obecnie hhvm 3.10
  43. 43. ASYNC DB QUERIES
  44. 44. ASYNC MYSQL mysqli::reap_async_query mysqli_reap_async_query
  45. 45. ASYNC POSTGRESQL
  46. 46. ASYNC HTTP
  47. 47. CURL_MULTI
  48. 48. BUZZ
  49. 49. BUZZMULTI
  50. 50. BUZZVS BUZZMULTI Time[ms] 0 1250 2500 3750 5000 Sync Multi Trudność w gromadzeniu requestów
  51. 51. GUZZLE 5 END OF SCRIPT http://www.rfc-editor.org/rfc/rfc1945.txt 200 http://www.rfc-editor.org/rfc/rfc7540.txt 200 http://www.rfc-editor.org/rfc/rfc2068.txt 200
  52. 52. composer require “guzzlehttp/guzzle:~5.3”
  53. 53. THREADS
  54. 54. YES! PHP Threads…
  55. 55. …and NOT pcntl_fork
  56. 56. https://pecl.php.net/package/pthreads https://github.com/krakjoe/pthreads http://php.net/pthreads
  57. 57. PTHREADS • Object Orientated (like Java) • Easy to use an safety built in (no MUTEX) • High level implementation of POSIX threads • Well documented
  58. 58. PTHREADS EXAMPLE
  59. 59. PTHREADS • Stable since 2013-09-08 (0.0.45) • Over 163,000 downloads (from PECL) • Heavily developed: (35 releases) • Mature
  60. 60. PTHREADS • http://pthreads.org/ • https://gist.github.com/krakjoe/9384409 • https://gist.github.com/krakjoe/6437782 read first
  61. 61. PTHREADS Not for web
  62. 62. –Joe Watkins “(…)you can't use pthreads safely and sensibly anywhere but CLI.”
  63. 63. PTHREADS PHP-CLI YES!
  64. 64. THREDS ARE HARD • https://web.stanford.edu/~ouster/cgi-bin/papers/ threads.pdf
  65. 65. OPERATOR OVERLOADING
  66. 66. OPERATOR OVERLOADING IN PHP EXTENSIONS
  67. 67. OPERATOR OVERLOADING IN PHP EXTENSIONS
  68. 68. THANKYOU https://joind.in/16171 @woocashw

×