PHPackages                             icicleio/icicle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. icicleio/icicle

ActiveLibrary[Queues &amp; Workers](/categories/queues)

icicleio/icicle
===============

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

v0.9.6(10y ago)1.1k150.9k↓31%42[2 issues](https://github.com/icicleio/icicle/issues)14MITPHPPHP ^5.5|^7.0

Since Mar 13Pushed 9y ago61 watchersCompare

[ Source](https://github.com/icicleio/icicle)[ Packagist](https://packagist.org/packages/icicleio/icicle)[ Docs](http://icicle.io)[ RSS](/packages/icicleio-icicle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (35)Used By (14)

**Icicle is now deprecated in favor of [Amp v2.0](http://amphp.org).** This version is is currently under development, but close to release. The v2.0 branches are *amp\_v2* in all packages except the [main Amp package](https://github.com/amphp/amp), loop package, and postgres package, where v2.0 is the *master* branch.

Icicle
======

[](#icicle)

**Icicle is a PHP library for writing *asynchronous* code using *synchronous* coding techniques.**

Icicle uses [Coroutines](https://icicle.io/docs/manual/coroutines/) built with [Awaitables](https://icicle.io/docs/manual/awaitables/) and [Generators](http://www.php.net/manual/en/language.generators.overview.php) to facilitate writing asynchronous code using techniques normally used to write synchronous code, such as returning values and throwing exceptions, instead of using nested callbacks typically found in asynchronous code.

[![Build Status](https://camo.githubusercontent.com/d581daea4dad921e4e4adb5e4920bceb602aac9716db127670cfa1208a4403f2/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696369636c65696f2f696369636c652f76312e782e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/icicleio/icicle)[![Coverage Status](https://camo.githubusercontent.com/13cbb17420099da4a148c5384b55991bfa29afcfcb232a0e831621f3f9be8500/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f696369636c65696f2f696369636c652f76312e782e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/icicleio/icicle)[![Semantic Version](https://camo.githubusercontent.com/760eddce1fa3faad83d3439895afa48ecffbb284bcbb2f890fb9167e34ad4e78/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f696369636c65696f2f696369636c652e7376673f7374796c653d666c61742d737175617265)](http://semver.org)[![MIT License](https://camo.githubusercontent.com/6e9bcd260ca8ad1ccfd80c9ee8f5b64c60017024c244afde455fb13badfbfb01/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696369636c65696f2f696369636c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![@icicleio on Twitter](https://camo.githubusercontent.com/fb16a2e03bb85dd9926a15e837d3754b7766046281e2698271930aadbcd972cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747769747465722d253430696369636c65696f2d3531383963372e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/icicleio)

#### Library Components

[](#library-components)

- **[Coroutines](https://icicle.io/docs/api/Coroutine/)** are interruptible functions for building asynchronous code using synchronous coding patterns and error handling.
- **[Awaitables](https://icicle.io/docs/api/Awaitable/)** act as placeholders for future values of asynchronous operations. Awaitables can be yielded in coroutines to define interruption points. Callbacks registered with awaitables may return values and throw exceptions.
- **[Observables](https://icicle.io/docs/api/Observable/)** represent asynchronous sets of values, providing operations usually associated with sets such as map, filter, and reduce. Observables also can be iterated over asynchronously within a coroutine.
- **[Loop (event loop)](https://icicle.io/docs/api/Loop/)** is used to schedule functions, run timers, handle signals, and poll sockets for pending data or await for space to write.

#### Available Packages

[](#available-packages)

- **[Stream](https://icicle.io/docs/api/Stream/)**: Common coroutine-based interface for reading and writing data.
- **[Socket](https://icicle.io/docs/api/Socket/)**: Asynchronous stream socket server and client.
- **[Concurrent](https://icicle.io/docs/api/Concurrent/)**: Provides an easy to use interface for parallel execution with non-blocking communication and task execution.
- **[DNS](https://icicle.io/docs/api/Dns/)**: Asynchronous DNS query executor, resolver and connector.
- **[Filesystem](https://github.com/icicleio/filesystem)**: Asynchronous filesystem access.
- **[HTTP](https://github.com/icicleio/http)**: Asynchronous HTTP server and client.
- **[WebSocket](https://github.com/icicleio/websocket)**: Asynchronous WebSocket server and client.
- **[React Adapter](https://github.com/icicleio/react-adapter)**: Adapts the event loop and awaitables of Icicle to interfaces compatible with components built for React.

#### Documentation and Support

[](#documentation-and-support)

- [Full API Documentation](https://icicle.io/docs/)
- [Official Twitter](https://twitter.com/icicleio)
- [Gitter Chat](https://gitter.im/icicleio/icicle)

##### Requirements

[](#requirements)

- PHP 5.5+ for v0.9.x branch (current stable) and v1.x branch (mirrors current stable)
- PHP 7 for v2.0 (master) branch supporting generator delegation and return expressions

##### Installation

[](#installation)

The recommended way to install Icicle is with the [Composer](http://getcomposer.org/) package manager. (See the [Composer installation guide](https://getcomposer.org/doc/00-intro.md) for information on installing and using Composer.)

Run the following command to use Icicle in your project:

```
composer require icicleio/icicle
```

You can also manually edit `composer.json` to add Icicle as a project requirement.

```
// composer.json
{
    "require": {
        "icicleio/icicle": "^0.9"
    }
}
```

##### Suggested

[](#suggested)

- [pcntl extension](http://php.net/manual/en/book.pcntl.php): Enables custom signal handling.
- [ev extension](https://pecl.php.net/package/ev): Extension providing the most performant event loop implementation.
- [uv extension](https://github.com/bwoebi/php-uv) (PHP 7 only): Another extension providing a more performant event loop implementation (experimental).

#### Example

[](#example)

The example script below demonstrates how [awaitables](https://icicle.io/docs/manual/awaitables/) can be yielded in a [coroutine](https://icicle.io/docs/manual/coroutines/) to create interruption points. Fulfillment values of awaitables are sent to the coroutine and rejection exceptions are thrown into the coroutine.

```
#!/usr/bin/env php
