PHP Fibers | Tomasz Turkowski

Discover the power of PHP Fibers, a simple mechanism for multitasking in PHP, allowing for asynchronous execution and cooperative multitasking, but not for direct developer use.

Key takeaways
  • PHP Fibers are a simple mechanism allowing for multitasking in PHP.
  • Fibers are not threads, but similar to coroutines or green threads.
  • Fibers are not intended for direct use by developers, but to be used with a scheduler or library.
  • The start method begins the fiber’s execution, and the suspend method pauses the fiber’s execution.
  • Fibers can be used to create asynchronous functions that can be suspended and resumed.
  • The isRunning, isSuspended, and isTerminated methods can be used to check the current state of a fiber.
  • Fibers are not blocking, but they can pause the entire execution stack.
  • The resume method is used to continue the execution of a suspended fiber.
  • Fibers can be used to run code asynchronously, but they are not meant to be used directly by developers.
  • PHP has a built-in fiber class, but it is still experimental and has limitations.
  • The yield method is not available in PHP Fibers, unlike in other languages.
  • Fibers can be used to create cooperative multitasking in PHP.
  • The main benefit of using Fibers is to separate the execution of code from the main execution stack.
  • Fibers are designed to be used in conjunction with a scheduler or library to achieve asynchronous execution.
  • The author is not aware of any current libraries or schedulers available for PHP Fibers.