0
0
PHPprogramming~5 mins

Fibers for concurrency in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Fiber in PHP?
A Fiber is a lightweight concurrency primitive that allows you to pause and resume code execution, enabling cooperative multitasking within a single thread.
Click to reveal answer
beginner
How do you create and start a Fiber in PHP?
You create a Fiber by instantiating the Fiber class with a callable, then start it using the start() method, which runs the fiber until it suspends or finishes.
Click to reveal answer
intermediate
What method do you use to pause a Fiber's execution?
You use the Fiber::suspend() method inside the fiber's callable to pause execution and optionally send a value back to the caller.
Click to reveal answer
intermediate
How do you resume a suspended Fiber?
You call the resume() method on the Fiber instance, optionally passing a value that the fiber receives as the result of the suspend() call.
Click to reveal answer
intermediate
Why are Fibers useful for concurrency in PHP?
Fibers let you write asynchronous code in a synchronous style by pausing and resuming tasks cooperatively, improving readability and control without using multiple threads.
Click to reveal answer
Which PHP class is used to create a Fiber?
AFiber
BThread
CCoroutine
DAsync
What method starts the execution of a Fiber?
Astart()
Bbegin()
Crun()
Dexecute()
How does a Fiber pause its execution?
AUsing yield
BUsing Fiber::suspend()
CUsing sleep()
DUsing wait()
What happens when you call resume() on a Fiber?
AIt stops the Fiber
BIt creates a new Fiber
CIt restarts the Fiber from the beginning
DIt continues execution from the last suspend point
Fibers in PHP help achieve concurrency by:
AUsing multiple processes
BRunning multiple threads simultaneously
CPausing and resuming code cooperatively in a single thread
DAutomatically parallelizing code
Explain how Fibers enable concurrency in PHP and how you control their execution.
Think about how you can stop and start a task manually inside one thread.
You got /4 concepts.
    Describe the lifecycle of a Fiber from creation to completion.
    Consider the steps you take to run, pause, and finish a Fiber.
    You got /5 concepts.