# start with 3 workers
docker compose up -d --scale worker=3
# verify that nginx and 3 workers are runing
docker compose ps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Generate prime numbers using the Sieve of Eratosthenes | |
// Lazily evaluted | |
// Inspired by: https://www.youtube.com/watch?v=5jwV3zxXc8E | |
$primes = sieve(nat(2)); | |
foreach ($primes as $value) { | |
echo $value . PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array Unpack | |
user: 4.355 ms | |
system: 0 ms | |
wait: 25 ms | |
total: 4.381 ms | |
Array Merge | |
user: 6.798 ms | |
system: 0 ms | |
wait: 7 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class BaseTestCase extends PHPUnit\Framework\TestCase | |
{ | |
/** | |
* Reset the properties to save memory after each test. | |
* @see https://kriswallsmith.net/post/18029585104/faster-phpunit | |
*/ | |
protected function tearDown(): void | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* @psalm-template TKey | |
* @psalm-template TValue | |
* @psalm-param iterable<TKey, TValue> $list | |
* @psalm-param callable(TValue): bool $filter | |
* @psalm-return Generator<TKey, TValue> | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace AppTest; | |
use PHPUnit\Framework\TestCase; | |
use Psr\Container\ContainerInterface; | |
use function assert; | |
use function strpos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$measure = function (callable $lambda) { | |
$rUsage = getrusage(); | |
$startUTime = $rUsage['ru_utime.tv_usec'] + $rUsage['ru_utime.tv_sec'] * 1000000; | |
$startSTime = $rUsage['ru_stime.tv_usec'] + $rUsage['ru_stime.tv_sec'] * 1000000; | |
$startHrTime = hrtime(true); | |
$lambda(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Traditional insert | |
INSERT INTO `campaigns` (name, active) VALUES ('foobar', 1⁾; | |
-- Alternative insert | |
INSERT INTO `campaigns` SET name = 'foobar', active = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Live Demo: https://3v4l.org/GWJFZ | |
// see also: http://0.30000000000000004.com/ | |
var_dump(0.1 + 0.2); // float(0.3) | |
var_dump(0.3); // float(0.3) | |
var_dump(0.1 + 0.2 == 0.3); // bool(false) | |
// Set the number of significant digits displayed in floating point numbers. | |
ini_set('precision', 18); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $clock implements Clock | |
// interface Clock | |
// { | |
// public function now() : DateTimeImmutable; | |
// } | |
// setup | |
$startDate = Date::fromString('2019-01-04'); |
NewerOlder