Content health: prewriting stage
This chapter is not yet finished. To speed up the progress, help us fix it at GitHub.

Asynchronous PHP

What is the difference between synchronous and asynchronous programming?

Synchronous programming is the most common and used way of writing and executing code. Code is executed statement by statement. Next statements don't get started until the previous statement is complete.

In asynchronous programming statements can start to perform before other statements are completed. Total time is reduced by minimizing the time spent waiting for operations to complete.

Main issue with asynchronous methodology is the dependency between the so called callbacks.

Terminology

To properly understand and have common grounds on this topic, some of the common terms will be explained below.

  • Concurency

    Concurency is ability of different program elements to be executed any order.

  • Coroutine

    Coroutines are program blocks (for example, functions), that can be suspened and resumed during the program execution.

Asynchronous programming in PHP

PHP doesn't provide any optimal means for asynchronous programming yet out-of-the-box. This can be solved using 3rd party PECL extensions or PHP libraries.

Standards

The PHP Asynchronous Interoperability Group has been formed to propose standards to PHP-FIG one day.

PHP libraries

PECL extensions

See also

Further resources to study the asynchronous topic in more details:



Found a typo? Something wrong with this content?

Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all contributors.