> > A SAPI is written in C (or at least, using > the C api's) and thus can do just about anything. If it wanted to, it could swap out > the global state when switching fibers. >
Probably, it's possible. However, if I'm not mistaken, $_GET and $_POST are implemented as regular PHP arrays, so if they need to be adapted, they should be replaced with proxy objects. > > So, at a minimum, I would guess the engine needs to provide hooks that the SAPI can use to provide request contexts to the global state > Thus, the cost of coroutine switching increases. Coroutines can switch between each other multiple times during a single SQL query. If there are 10-20 such queries, the total number of switches can reach hundreds. Using the proxy pattern is the most common practice in this case. > > If fibers were to allow true concurrency, we would need many more primitives. > You mean true parallelism. If that happens, all existing PHP frameworks, libraries, and C extensions would have to be rewritten, sometimes almost from scratch. But it would most likely be a different language. Ed.