Asynchronous non-blocking I/O calls

As we have seen in the previous chapters of this book, I/O calls will always offer the worst performance due to the underlying latency of establishing, using and closing streams and sockets. Since PHP is basically a synchronous language that waits for a called function to return before resuming code execution, I/O calls are especially problematic if the called function has to wait for a stream to close before returning to the calling code. This becomes even worse when a PHP application has thousands of I/O calls to do every few minutes for example.

Since PHP 5.3, it has become possible to interrupt PHP's normal flow of execution by using generators and thus, to execute code asynchronously. As we have seen ...

Get Mastering The Faster Web with PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.