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: