PHP has no multithreading in the language syntax itself, but concurrency is still available through extensions and runtime features.
| Feature | Description | Since / notes |
|---|---|---|
| Fibers | Coroutines that can be suspended and resumed. They are not executed in parallel. | PHP 8.1+ |
| PCNTL | Process forking: isolated child processes with separate memory. | Unix/CLI; process-based parallelism |
| pthreads | True OS threads that share memory inside one process. | Requires ZTS PHP build |
| Daemons | Running a PHP script as a long-lived background process. | CLI, nohup + & |
Process vs thread
A process is a running program. The operating system gives it:
- Its own address space (isolated from other processes).
- Executable code loaded into that address space.
- Memory allocated as needed.
- Descriptors (open files, network connections, and so on).
A thread of execution is the smallest unit of code that the OS can schedule:
- A thread lives inside a process.
- Every process starts with at least one thread.
- Threads in the same process share code, context (for example global variables), and memory.
- Multiple threads are like several cooks preparing one dish from the same recipe.
On a single core, threads take turns via context switching. That switch is still cheaper than switching between processes. On a multi-core system, threads can run truly in parallel, one per core.
Because threads share memory, they can read and change the same globals without special IPC — which also means you need synchronization to avoid race conditions.
Fibers
Good explanation: open_in_new PHP 8.1 Fibers .
Use fibers when you want cooperative concurrency in one process — for example to show progress of another operation (copying files, updating a database) without blocking the whole script forever. Fibers do not give you parallel CPU work the way processes or OS threads do.
Andrew Dorokhov