SlideShare a Scribd company logo
Building an Incredible Machine
With Generators and Pipelines in PHP
by Dan Leech
@dantleech
g
b
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
/**
* @Revs(1000)
* @Iterations(10)
*/
class HashingBench
{
public function benchMd5()
{
md5('hello world');
}
public function benchSha1()
{
sha1('hello world');
}
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
No way to interpolate tests
Three Benchmarks
Linear Execution
Linear Execution
Interpolated Execution
The results are now consistently inconsistent
PHPBench will report a high standard deviation, and you will
know to start again.
Instant Comparison
By interpolating tests we can provide faster
feedback to the user
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Can I do this with Iterators?
Can I do this with Generators?
Generators
PHP 5.5.0
20 June 2013
Generators are Iterators
<?php
$iterator = new ArrayIterator([
‘key1’ => ‘value1’,
‘key2’ => ‘value2’,
]);
foreach ($iterator as $key => $value) {
echo “{$key} {$value}”;
}
AppendIterator
ArrayIterator
CachingIterator
CallbackFilterIterator
DirectoryIterator
EmptyIterator
FilesystemIterator
FilterIterator
AppendIterator
ArrayIterator
CachingIterator
CallbackFilterIterator
DirectoryIterator
EmptyIterator
FilesystemIterator
FilterIterator
GlobIterator
InfiniteIterator
IteratorIterator
LimitIterator
MultipleIterator
← Pseudo-type accepting arrays and Traversable (7.1)
← Cannot implement
<?php
function dump_many(iterable $iterable)
{
foreach ($iterable as $value) {
var_dump($value);
}
}
dump_many(['one', 'two', 'three']);
dump_many(new ArrayObject(['one', 'two', 'three']));
// string(3) "one"
// string(3) "two"
// string(5) "three"
// string(3) "one"
// string(3) "two"
// string(5) "three"
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
class MyAwesomeIterator implements Iterator {
private $myArray;
public function __construct(array $myArray) {
$this->myArray = $myArray;
}
function rewind() {
return reset($this->myArray);
}
function current() {
return current($this->myArray);
}
function key() {
return key($this->myArray);
}
function next() {
return next($this->myArray);
}
function valid() {
return key($this->myArray) !== null;
}
Generators are easy Iterators
That you cannot rewind
But that's OK, because they do cool stuff
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Iterator
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Generator
YIELD
function numbers(): Generator
{
yield "1";
yield "2";
yield "3";
}
foreach (numbers() as $number) {
echo $number;
}
// 123
Yielding control
<?php
function lines($fileName)
{
$h = fopen($fileName, 'r');
$lines = [];
while (false !== $line = fgets($h)) {
$lines[] = $line;
}
fclose($h);
return $lines;
}
foreach (lines() as $line) {
echo $line;
}
Example with standard array
<?php
function lines($fileName)
{
$h = fopen($fileName, 'r');
while (false !== $line = fgets($h)) {
yield $line;
}
fclose($h);
}
foreach (lines() as $line) {
echo $line;
// do something else
Example with generator
Generators make functions interruptible
final class Generator implements Iterator {
function rewind() {}
function valid() {}
function current() {}
function key() {}
function next() {}
function send($value) {}
function throw(Exception $exception) {}
function getReturn() {}
}
Generator
send()
send()
function myGenerator(): Generator
{
$data = yield;
yield $data;
}
echo myGenerator()->send('Goodbye');
// Goodbye
Fast forwards to first yield returns
the sent value
send()
<?php
function echoGenerator(): Generator
{
$data = yield;
$data = yield $data;
}
$generator = echoGenerator();
var_dump($generator->send('Hello'));
var_dump($generator->send('Goodbye'));
var_dump($generator->send('Adios'));
send()
string(5) "Hello"
NULL
NULL
throw()
throw()
function myGenerator(): Generator
{
try {
yield;
} catch (MyException $e) {
echo 'Hello!';
}
}
echo myGenerator()->throw(new MyException());
Exception thrown here
invalid generator
function myGenerator(): Generator
{
try {
yield;
} catch (MyException $e) {
echo 'Hello!';
}
}
$generator = myGenerator();
$generator->next();
echo myGenerator()->throw(new MyException());
Exception thrown here
getReturn()
getReturn
<?php
function hello(): Generator
{
yield 'hello';
yield 'goodbye';
return 'ciao';
}
$generator = hello();
echo $generator->getReturn();
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
PHP Fatal error: Uncaught Exception: Cannot get
return value of a generator that hasn't returned
getReturn
<?php
function hello(): Generator
{
yield 'hello';
yield 'goodbye';
return 'ciao';
}
$generator = hello();
$generator->next()
$generator->next();
echo $generator->getReturn();
// ciao
Generators will not return the return value
Unless you call getReturn()
After the generator has returned
Asynchronous Operations
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Async Operations
function requestUrl($url): Generator {
$process = new Process("curl -I $url");
$process->start();
while ($process->isRunning()) {
echo $url . "n";
yield;
}
yield $process->getOutput();
}
WARNING: This code is terrible, please do not use it
Async Operations
$generators = [
requestUrl('https://inviqa.com'),
requestUrl('https://bbc.co.uk'),
];
while ($generators) {
foreach ($generators as $i => $gen) {
$result = $gen->current()
if ($result !== false) {
var_dump($result); // success!!!
}
$gen->next();
if ($gen->valid() === false) {
unset($generators[$i]);
}
}
WARNING: This code is terrible, please do not use it
https://www.inviqa.com
https://www.inviqa.com
http://www.bbc.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
http://www.bbc.com
https://www.inviqa.com
string(344) "HTTP/1.1 301 Moved Permanently
Date: Tue, 20 Feb 2018 21:21:23 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Tue, 20 Feb 2018 22:21:23 GMT
Location: http://inviqa.com/
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-
cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 3f0483ebdb3a2d6b-TXL
string(612) "HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html
Expires: Tue, 20 Feb 2018 21:21:32 GMT
Content-Language: en
Etag: "25e4bf9a0519a562c8fb0a6379044365"
X-PAL-Host: pal143.back.live.telhc.local:80
Content-Length: 209756
Date: Tue, 20 Feb 2018 21:21:23 GMT
Connection: keep-alive
Set-Cookie: BBC-
UID=055ac8cca981056306da9a3821c959a1b1d799b4875494361aa037e2fe86c6080curl/7.55.1;
expires=Sat, 19-Feb-22 21:21:23 GMT; path=/; domain=.bbc.com
Cache-Control: private, max-age=60
X-Cache-Action: HIT
X-C"...
Go and look at event loops
AMP
Amp is a non-blocking concurrency
framework for PHP. It provides an event
loop, promises and streams as a base for
asynchronous programming.
Promises in combination with generators
are used to build coroutines, which allow
writing asynchronous code just like
synchronous code, without any callbacks.
https://github.com/amphp/amp
AMP
Amp is a non-blocking concurrency
framework for PHP. It provides an event
loop, promises and streams as a base for
asynchronous programming.
Promises in combination with generators
are used to build coroutines, which allow
writing asynchronous code just like
synchronous code, without any callbacks.
https://github.com/amphp/amp
Infinite Potential
while (true)
<?php
function natural_numbers($number = 1): Generator
{
while (true) {
yield $number++;
}
}
foreach (numbers() as $number) {
echo $number . ' ';
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
108 109 110 111 112 113 114 115 116 117 118 ...
The number of iterations is no longer the concern
of the generator
Recursion
function myGenerator(): Generator
{
$count = yield;
while (true) {
$count = $count * 2;
$count = yield $count;
}
}
$generator = myGenerator();
$count = 1;
while (true) {
$count = $generator->send($count);
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Pipelines
A pipeline is a sequence of stages.
Each stage has a specific job to do.
1)Make each program do one thing well. To do a new job, build afresh
rather than complicate old programs by adding new "features".
2)Expect the output of every program to become the input to another, as yet
unknown, program. Don't clutter output with extraneous information. Avoid
stringently columnar or binary input formats. Don't insist on interactive
input.
3)Design and build software, even operating systems, to be tried early,
ideally within weeks. Don't hesitate to throw away the clumsy parts and
rebuild them.
4)Use tools in preference to unskilled help to lighten a programming task,
even if you have to detour to build the tools and expect to throw some of
them out after you've finished using them.
Unix Philosophy
1)Make each program do one thing well. To do a new job, build afresh
rather than complicate old programs by adding new "features".
2)Expect the output of every program to become the input to another, as yet
unknown, program. Don't clutter output with extraneous information. Avoid
stringently columnar or binary input formats. Don't insist on interactive
input.
3)Design and build software, even operating systems, to be tried early,
ideally within weeks. Don't hesitate to throw away the clumsy parts and
rebuild them.
4)Use tools in preference to unskilled help to lighten a programming task,
even if you have to detour to build the tools and expect to throw some of
them out after you've finished using them.
Unix Philosophy
Unix Pipes
$ echo '<?php echo "hello";' | php
hello
This is a simple phraze this is
Spell Checker
$ echo 'This is a a simple phraze this is'
Command
Output
This
is
a
simple
phraze
this
is
Spell Checker
$ echo 'This is a simple phraze this is' |
words
Command
Output
this
is
a
simple
phraze
this
is
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase
Command
Output
a
is
is
phraze
simple
this
this
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort
Command
Output
a
is
phraze
simple
this
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort |
unique
Command
Output
phraze
Spell Checker
$ echo 'This is a simple phraze' |
words |
lowercase |
sort |
unique |
mismatch dictionary.txt
Command
Output
That wasn't GNU
Stage GNU
words fmt -1
lowercase tr '[:upper:]' '[:lower:]'
sort sort
unique uniq
mismatch dictionary.txt comm -23 - dictionary.txt
Working together + Specialisation
Pipelines in PHP
Input
Callable
Stage
Output
Stage
Stage
Input
Callable
Callable
Output
Callable
Callable function ($value) { return $value * 2; }
10
20
function ($value) { return $value +1; }
21
function ($value) { return $value * 2; }
42
$pipeline = (new Pipeline)
->pipe(function ($value) {
return $value * 2;
})
->pipe(function ($value) {
return $value +1;
})
->pipe(function ($value) {
return $value * 2;
})
;
$pipeline->process(10);
class TimesTwoStage {
public function __invoke($value) {
return $value * 2;
}
}
class AddOneStage {
public function __invoke($value) {
return $value + 1;
}
}
$pipeline = (new Pipeline)
->pipe(new TimesTwoStage())
->pipe(new AddOneStage())
->pipe(new TimesTwoStage());
$pipeline->process(10);
Stages can be Generators
function Stage1(): Generator
{
$payload = yield;
while (true) {
$data = yield data;
}
}
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Let's build a thing!
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)
Thanks
Blog Posts
●
https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html
●
https://blog.ircmaxell.com/2012/07/what-generators-can-do-for-you.html
● https://speakerdeck.com/chrispitt/cooperative-multitasking-with-generators
– https://www.youtube.com/watch?v=cY8FUhZvK7w
●
https://medium.com/@aaronweatherall/the-pipeline-pattern-for-fun-and-profit-9b5f43a98130
●
https://www.cise.ufl.edu/research/ParallelPatterns/PatternLanguage/AlgorithmStructure/Pipeline.htm
● https://markbakeruk.net/2016/01/19/a-functional-guide-to-cat-herding-with-php-generators/
● http://sergeyzhuk.me/2018/02/15/amp-coroutines/
●
https://medium.com/ifixit-engineering/functional-programming-with-php-generators-837a6c91b0e3
● https://www.entropywins.wtf/blog/2017/10/16/introduction-to-iterators-and-generators-in-php/
●
http://blog.kevingomez.fr/2016/01/20/use-cases-for-php-generators/
Videos
● Cooperative multitasking with Generators:
https://www.youtube.com/watch?v=cY8FUhZvK7w
● Pushing the limits of PHP with React:
https://www.youtube.com/watch?
v=fQxxm4vD8Ok&feature=youtu.be
● Herding Cats: https://vimeo.com/189755262
● What the heck is the event loop anyway?:
https://www.youtube.com/watch?v=8aGhZQkoFbQ
Use Generators NOW!
● Importing Data
● Data providers in PHPUnit (and PHPBench!)
Before
/**
* @dataProvider provideMultiplies
*/
function testMultiplies($v, $m, $expected) {
$result = $this->multiplier->multiply($v, $m);
$this->assertEquals($expected, $result);
}
public function provideMultiplies()
{
return [
'one times one' => [ 1, 1, 1 ],
'two times two' => [ 2, 2, 4 ],
];
}
After
/**
* @dataProvider provideMultiplies
*/
function testMultiplies($v, $m, $expected) {
$result = $this->multiplier->multiply($v, $m);
$this->assertEquals($expected, $result);
}
public function provideMultiplies()
{
yield 'one times one' => [ 1, 1, 1 ];
yield 'two times two' => [ 2, 2, 4 ];
}
● Saved 2 lines of code
● Looks nicer
● Not actually lazy ... but it could be!

More Related Content

What's hot (20)

PDF
IoT Best practices
CocoaHeads France
 
PDF
Building Testable PHP Applications
chartjes
 
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
James Titcumb
 
PDF
Symfony2 revealed
Fabien Potencier
 
PDF
Diving into HHVM Extensions (php[tek] 2016)
James Titcumb
 
PDF
PyCon lightning talk on my Toro module for Tornado
emptysquare
 
PDF
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
PDF
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
PDF
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
Jim Mlodgenski
 
DOCX
VPN Access Runbook
Taha Shakeel
 
PDF
What's new in PHP 8.0?
Nikita Popov
 
PDF
Currying and Partial Function Application (PFA)
Dhaval Dalal
 
PDF
Node Boot Camp
Troy Miles
 
PDF
Advanced functional programing in Swift
Vincent Pradeilles
 
PDF
Découvrir dtrace en ligne de commande.
CocoaHeads France
 
PDF
Creating Lazy stream in CSharp
Dhaval Dalal
 
PDF
Monads in Swift
Vincent Pradeilles
 
PDF
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
PDF
RxSwift to Combine
Bo-Young Park
 
PDF
Workshop 10: ECMAScript 6
Visual Engineering
 
IoT Best practices
CocoaHeads France
 
Building Testable PHP Applications
chartjes
 
Diving into HHVM Extensions (PHPNW Conference 2015)
James Titcumb
 
Symfony2 revealed
Fabien Potencier
 
Diving into HHVM Extensions (php[tek] 2016)
James Titcumb
 
PyCon lightning talk on my Toro module for Tornado
emptysquare
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
Jim Mlodgenski
 
VPN Access Runbook
Taha Shakeel
 
What's new in PHP 8.0?
Nikita Popov
 
Currying and Partial Function Application (PFA)
Dhaval Dalal
 
Node Boot Camp
Troy Miles
 
Advanced functional programing in Swift
Vincent Pradeilles
 
Découvrir dtrace en ligne de commande.
CocoaHeads France
 
Creating Lazy stream in CSharp
Dhaval Dalal
 
Monads in Swift
Vincent Pradeilles
 
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
RxSwift to Combine
Bo-Young Park
 
Workshop 10: ECMAScript 6
Visual Engineering
 

Similar to Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin) (20)

ODP
Incredible Machine with Pipelines and Generators
dantleech
 
PDF
Generating Power with Yield
Jason Myers
 
PPTX
Electrify your code with PHP Generators
Mark Baker
 
PPTX
Generated Power: PHP 5.5 Generators
Mark Baker
 
PDF
Cryptography in PHP: use cases
Enrico Zimuel
 
PDF
잘 알려지지 않은 Php 코드 활용하기
형우 안
 
PDF
ReactPHP
Philip Norton
 
PDF
PHP Generators
Simone Di Maulo
 
PDF
Go from PHP engineer's perspective
Sobit Akhmedov
 
PDF
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
Raul Fraile
 
PPTX
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
PDF
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Lyon Yang
 
PDF
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
PDF
08 Advanced PHP #burningkeyboards
Denis Ristic
 
PDF
Gearman - Northeast PHP 2012
Mike Willbanks
 
PDF
Living With Legacy Code
Rowan Merewood
 
PPTX
php programming.pptx
rani marri
 
ODP
The promise of asynchronous PHP
Wim Godden
 
PDF
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
ODP
PHP5.5 is Here
julien pauli
 
Incredible Machine with Pipelines and Generators
dantleech
 
Generating Power with Yield
Jason Myers
 
Electrify your code with PHP Generators
Mark Baker
 
Generated Power: PHP 5.5 Generators
Mark Baker
 
Cryptography in PHP: use cases
Enrico Zimuel
 
잘 알려지지 않은 Php 코드 활용하기
형우 안
 
ReactPHP
Philip Norton
 
PHP Generators
Simone Di Maulo
 
Go from PHP engineer's perspective
Sobit Akhmedov
 
$kernel->infect(): Creating a cryptovirus for Symfony2 apps
Raul Fraile
 
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Lyon Yang
 
Debugging: Rules And Tools - PHPTek 11 Version
Ian Barber
 
08 Advanced PHP #burningkeyboards
Denis Ristic
 
Gearman - Northeast PHP 2012
Mike Willbanks
 
Living With Legacy Code
Rowan Merewood
 
php programming.pptx
rani marri
 
The promise of asynchronous PHP
Wim Godden
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 
PHP5.5 is Here
julien pauli
 
Ad

More from dantleech (7)

PDF
2019 11-bgphp
dantleech
 
PDF
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
ODP
Phpactor and VIM
dantleech
 
ODP
A Tale of Three Components
dantleech
 
PDF
Boltc CMS - a really quick overview
dantleech
 
PDF
Tmux quick intro
dantleech
 
PDF
Benchmarking and PHPBench
dantleech
 
2019 11-bgphp
dantleech
 
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
Phpactor and VIM
dantleech
 
A Tale of Three Components
dantleech
 
Boltc CMS - a really quick overview
dantleech
 
Tmux quick intro
dantleech
 
Benchmarking and PHPBench
dantleech
 
Ad

Recently uploaded (20)

PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Digital Circuits, important subject in CS
contactparinay1
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 

Building and Incredible Machine with Pipelines and Generators in PHP (IPC Berlin)

Editor's Notes

  • #2: In this talk we will briefly discuss a specific problem in PHPBench (a benchmarking tool for PHP) which can be solved through the use of Generators (and pipelines!). We will then explore both topics generally, before combining them into an Incredible Machine in a live coding session.
  • #4: I was on the bench at the beginning of this month. I was wondering what to do Then I remembered that I always intended to make PHPBench better...
  • #6: - Explain better what this does - Why are you doing things with hashes
  • #14: Composition Making a system
  • #15: Iterators rotate
  • #16: Generators can pass values to each other while rotating
  • #20: - Iterators can have state - Get values from a database - Generate values
  • #23: - Iterators can have state - Get values from a database - Generate values
  • #24: Doctrine ORM Example
  • #25: Native PHP array functions counterparts
  • #27: The type hierarchy - Iterable: PHP 7.1 - Pseudo type - array - Traversable: System type - Iterator - Iterator Aggregate
  • #32: Same as passing [1,2,3] to the built in array-iterator (next slide)
  • #35: Control is being passed from the generator to the for loop
  • #40: - What is going to happen here - Value is returned by yield
  • #41: - Value is returned by yield -
  • #43: &amp;lt;REVIEW!!&amp;gt;
  • #44: - Sending signals to the generator (e.g. close file) - ...?
  • #49: Get return allows you to retrieve the value
  • #55: - *PHP is async* - Replace somethingElse (AccessDatabase, concurrent HTTP requests).
  • #56: - *PHP is async* - Replace somethingElse (AccessDatabase, concurrent HTTP requests).
  • #64: Generators can be chained to each other
  • #93: - Tests are interpolated - Instant comparison - View evolution of tests - Timed tests (remember Infinite!)