switch ($texan) { case "y'all": return "some of you"; case "all y'all": return "all of you"; default: return $texan; }
function gRange($min, $max, $step): \Generator { for ($i = $min; $i < $max; $i += $step) { yield $i; } } foreach (gRange(12, 82, 5) as $n) { echo "$n\n"; // 12, 17, 22, etc. }
function spooky(): \Generator { while (true) { yield random_int(0, 1) ? 'O' : 'o'; } } foreach (spooky() as $chr) { echo $chr; usleep(100000); }
If you call a function that yields, you will not execute that function. You'll get back a Generator object. To execute the function, you need to call methods on the Generator.
Also, "return" means something different for a Generator than for a normal function.
$g = gen(1);
$a = $g->current();
2
$b = yield $arg1 + 1;
$c = $g->send($a + 1);
$d = yield $b + 2;
5
3
function gen($arg1)
$e = $g->send($c + 1);
6
return $d + 2;
null
echo $g->getReturn();
8
* Ignoring curl_multi and wrappers (e.g. Guzzle)
var_dump(is_12_factor()); // bool(true)
* Throwables to the rescue!
** amphp/cluster to the rescue!
siege -c 15 -t 30S -b <url> <cookie header>
Transactions: 17029 hits Availability: 100.00 % Elapsed time: 29.25 secs Data transferred: 0.68 MB Response time: 0.03 secs Transaction rate: 582.19 trans/sec Throughput: 0.02 MB/sec Concurrency: 14.95 Successful transactions: 17029 Failed transactions: 0 Longest transaction: 0.07 Shortest transaction: 0.00
~45MB RAM, ~120% CPU
Transactions: 20724 hits Availability: 99.57 % Elapsed time: 29.79 secs Data transferred: 0.96 MB Response time: 0.02 secs Transaction rate: 695.67 trans/sec Throughput: 0.03 MB/sec Concurrency: 14.84 Successful transactions: 20724 Failed transactions: 90 Longest transaction: 1.04 Shortest transaction: 0.00
~42MB RAM, ~120% CPU