### PHP Fibers
## the New Controversial PHP 8.1 Feature Not For You
### In previous episode:
* [Slides](https://bullder.github.io/async/)
* [Video](https://youtu.be/7R0jjMAwja8)
### [RFC:Fibers](https://wiki.php.net/rfc/fibers)
```[php] [|3|4-6|7-8|10-14]
final class Fiber
{
public function __construct(callable $callback) {}
public function start(mixed ...$args): mixed {}
public function resume(mixed $value = null): mixed {}
public function throw(Throwable $exception): mixed {}
public static function this(): ?self {}
public static function suspend(mixed $value = null): mixed {}
public function isStarted(): bool {}
public function isSuspended(): bool {}
public function isRunning(): bool {}
public function isTerminated(): bool {}
public function getReturn(): mixed {}
}
```
### Usage
```[php] [|1-4|6|2|7|8|3]
$fiber = new Fiber(function (): void {
$value = Fiber::suspend('fiber');
echo "Value used to resume fiber: ", $value, "\n";
});
$value = $fiber->start();
echo "Value from fiber suspending: ", $value, "\n";
$fiber->resume('test');
```
### Is it Fibers ready to use?
* Support with high-level frameworks (Symfony, Laravel) not clear (UPD: [Symfony process](https://github.com/symfony/symfony/pull/43678/files))
* Support with low-level frameworks (amphp, ReactPHP) is under development (UPD: [revoltphp](https://github.com/revoltphp/event-loop))
* Theoretically that should not be in PHP-core
### You Won’t Use Fibers Directly
* [only the bare minimum](https://wiki.php.net/rfc/fibers#why_not_add_an_event_loop_and_asyncawait_api_to_core)
* No event loop and no scheduler. No async/await
* Only one fiber at a time can be executed (No data races, no semaphores, and no mutexes)
* No channels
* All code must be async
* Is it nice feature?
### Interactive part:
* [Play with async PHP](https://bullder.github.io/async/#/3)
* [Research about RoadRunner by Spiral Scout](https://roadrunner.dev/)
* [Jarvis Stand-up Notifier](http://gitlab.production.smartbox.com/michael.garifullin/jarvis-notify/)
* [Jarvis Deploy Notifier](http://gitlab.production.smartbox.com/Andrei.Caprar/notify/-/blob/master/notify.go)
### Might be fun:
* [PHP Internals News #74 Fibers](https://phpinternals.news/74)
* [RFC Discussion thread](https://externals.io/message/113430)
* [What Color is Your Function?](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/)
* [Server-side I/O Performance: Node vs. PHP vs. Java vs. Go](https://www.toptal.com/back-end/server-side-io-performance-node-php-java-go)
* [6 months with GoLang after many years with PHP](https://medium.com/efesent-solutions/6-months-with-golang-after-many-years-with-php-c52124fb7da)