Build fast, concurrent applications with PHP

Benefit from concurrency by replacing your blocking I/O with non-blocking I/O,
or designing your system with non-blocking I/O from the ground up.

We shipped fibers in PHP 8.1 to extend its capabilities for concurrent applications.

The PHP standard library has already provided everything else we needed for years now, but it only ships the low-level building blocks. AMPHP provides higher-level libraries using non-blocking I/O under the hood. Fibers allow these libraries to just work, no matter whether they're used in concurrent or traditional contexts.

Latest Releases

  • Released on 2024-02-28 2.2.4 on GitHub

    amphp/socket 2.2.4

    What’s Changed

    • Removed missed call to stream_context_set_option(), which was causing a deprecation notice on PHP 8.3.

    Full Changelog: https://github.com/amphp/socket/compare/v2.2.3…v2.2.4

  • Released on 2024-02-17 2.1.1 on GitHub

    amphp/byte-stream 2.1.1

    What’s Changed

    • Fixed cancellation not being forwarded to split() in splitLines().

    Full Changelog: https://github.com/amphp/byte-stream/compare/v2.1.0…v2.1.1

  • Released on 2024-02-17 2.0.2 on GitHub

    amphp/process 2.0.2

    What’s Changed

    • Changed waiting for children during shutdown to be synchronous to ensure all children are properly cleaned up. This should avoid zombie processes left when running within an SAPI such as PHP-FPM.
    • Fixed UnhandledFutureError being thrown to event loop if reading the process exit code fails.

    Full Changelog: https://github.com/amphp/process/compare/v2.0.1…v2.0.2

  • Released on 2024-02-01 2.1.1 on GitHub

    amphp/dns v2.1.1

    What’s Changed

    • Corrected error message unit scale (ms -> seconds) by @Bilge in https://github.com/amphp/dns/pull/113
    • Fixed Windows nameserver detection by only enumerating real NICs by @Bilge in https://github.com/amphp/dns/pull/114

    New Contributors

    • @Bilge made their first contribution in https://github.com/amphp/dns/pull/113

    Full Changelog: https://github.com/amphp/dns/compare/v2.1.0…v2.1.1

  • Released on 2024-01-30 1.0.1 on GitHub

    amphp/windows-registry 1.0.1

    What’s Changed

    • Removed nullability from return type of WindowsRegistry::read(), the method throws if the key is not found.

    Full Changelog: https://github.com/amphp/windows-registry/compare/v1.0.0…v1.0.1

  • Released on 2024-01-07 2.2.6 on GitHub

    amphp/parallel 2.2.6

    What’s Changed

    • Fixed hang during shutdown if a process or thread context has not ended (fixes amphp/file#75).

    Full Changelog: https://github.com/amphp/parallel/compare/v2.2.5…v2.2.6

  • Released on 2023-12-29 4.0.0 on GitHub

    amphp/websocket-server 4.0.0

    The 4.0.0 release fixes compression support with a couple small compatibility breaks from 3.x.

    Users of 2.x should upgrade directly to 4.0.0.

    Users of 3.x can upgrade directly to 4.0.0 if compression is not being used. If a custom WebsocketAcceptor was created to support compression, this custom implementation may be dropped, instead passing an instance of WebsocketCompressionContextFactory to each Websocket request handler.

    Backward Compatibility Breaks

    • The WebsocketCompressionContextFactory constructor parameter of Rfc6455ClientFactory has been removed and is instead a constructor parameter of the Websocket class.
    • A nullable WebsocketCompressionContext parameter was added to WebsocketClientFactory::createClient().
  • Released on 2023-12-28 2.0.3 on GitHub

    amphp/websocket 2.0.3

    What’s Changed

    • WebsocketException now extends Amp\ByteStream\StreamException to avoid violating the ReadableStream interface by throwing a non-StreamException from a stream method.

    Full Changelog: https://github.com/amphp/websocket/compare/v2.0.2…v2.0.3

  • Released on 2023-12-28 3.3.0 on GitHub

    amphp/http-server 3.3.0

    What’s Changed

    • RequestBody now implements Stringable so the entire request body can be buffered by simply casting the object to a string (note the request body length limits still apply).
    • Fixed the HTTP/2 initial window size being potentially larger than the client would accept.
    • Fixed incrementing the HTTP/2 window size if the body size limit is very large.
    • ClientException now extends Amp\ByteStream\StreamException to avoid violating the ReadableStream interface by throwing a non-StreamException from a stream method.

    New Contributors

    • @cwhite92 made their first contribution in https://github.com/amphp/http-server/pull/353
    • @foremtehan made their first contribution in https://github.com/amphp/http-server/pull/356

    Full Changelog: https://github.com/amphp/http-server/compare/v3.2.0…v3.3.0

  • Released on 2023-12-28 2.0.0 on GitHub

    amphp/websocket-client 2.0.0

    Stable release compatible with AMPHP v3 and fibers! 🎉

    As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType> have been replaced with ResolutionType.

    This release is compatible with amphp/http-client@^5 and amphp/websocket@^2. See the release notes of these libraries for further change notes.

    Similar to v1, a Websocket connection is created using Amp\Websocket\Client\connect() or using an instance of WebsocketConnector, calling WebsocketConnector::connect(). The returned WebsocketConnection then is used to send and receive WebSocket messages.

    • Renamed most classes and interfaces to add Websocket as a prefix to avoid name collisions with similarly named classes in other packages which are frequently used together. For example, Connection is now WebsocketConnection.
    • Advanced handshake and connection parameters may be specified using a Rfc6455ConnectionFactory instance provided when constructing a Rfc6455Connector.
    • A global WebsocketConnector instance may be accessed and set via Amp\Websocket\Client\websocketConnector().
  • Released on 2023-12-27 3.0.2 on GitHub

    amphp/file 3.0.2

    What’s Changed

    • Fixed detecting if a file is writing from the file mode when r+ (or similar) is used as the mode. (#77)
    • Fixed assertion failing during shutdown destruction of ParallelFilesystemDriver. (#81)

    Full Changelog: https://github.com/amphp/file/compare/v3.0.1…v3.0.2

  • Released on 2023-12-23 1.1.0 on GitHub

    amphp/pipeline 1.1.0

    • Added Pipeline::merge() which combines multiple iterators, emitting a value whenever any iterator emits a value.
    • Fixed Pipeline::take() not completing until a value beyond the given count was emitted. The pipeline now completes immediately after emitting the last view.
    • Marked the template type of ConcurrentIterator as covariant.
  • Released on 2023-12-11 5.0.1 on GitHub

    amphp/http-client 5.0.1

    What’s Changed

    • Fail streams only with StreamException by @trowski in https://github.com/amphp/http-client/pull/354. Response body streams will now only throw StreamException or CancelledException as specified by the ReadableStream interface.

    Full Changelog: https://github.com/amphp/http-client/compare/v5.0.0…v5.0.1

  • Released on 2023-12-03 2.0.1 on GitHub

    amphp/php-cs-fixer-config 2.0.1

    • Removed deprecated rules (#7)

    Full Changelog: https://github.com/amphp/php-cs-fixer-config/compare/v2.0.0…v2.0.1

  • Released on 2023-11-25 2.0.0 on GitHub

    amphp/parallel-functions 2.0.0

    Stable release compatible with AMPHP v3 and fibers! 🎉

    As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType> have been replaced with ResolutionType.

  • Released on 2023-10-08 2.0.0 on GitHub

    amphp/http-client-cookies 2.0.0

    Stable release compatible with AMPHP v3 and fibers! 🎉

    As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType> have been replaced with ResolutionType.

    • Renamed InMemoryCookieJar to LocalCookieJar
  • Released on 2023-09-05 3.2.0 on GitHub

    amphp/hpack 3.2.0

    • Improved detection of libnghttp2, i.e. libnghttp2.so.14 and looking in the Homebrew path

    Full Changelog: https://github.com/amphp/hpack/compare/v3.1.7…v3.2.0

  • Released on 2023-08-25 2.0.0 on GitHub

    amphp/http-server-form-parser 2.0.0

    This release is compatible with amphp/http-server@^3.

    • Renamed BufferingParser and StreamingParser to FormParser and StreamingFormParser, respectively.
    • Removed the parseForm function in favor of the Form::fromRequest() static method.
    • Removed ParsingMiddleware. Use Form::fromRequest() instead.
    • Removed ParseException. Form parsing errors will throw an HttpErrorException from amphp/http-server instead, which do not need to be caught (the server will automatically return an error response).
  • Released on 2023-08-24 2.1.0 on GitHub

    amphp/http 2.1.0

    • Updated league/uri-components requirements to ^2.4.2 | ^7.1 as part of fixing #24 and allow psr/message@v2
    • Changed request query string encoding to use RFC3986 rules to as part of fixing #24

    Full Changelog: https://github.com/amphp/http/compare/v2.0.0…v2.1.0

  • Released on 2023-08-20 3.0.0 on GitHub

    amphp/http-server-session 3.0.0

    This release is compatible with amphp/http-server@^3.

    • Renamed Storage, InMemoryStorage, RedisStorage, DefaultIdGenerator, and Driver to SessionStorage, LocalSessionStorage, RedisSessionStorage, Base64UrlSessionIdGenerator, and SessionFactory, respectively
    • Renamed methods on Session: open() to lock(), save() to commit()
    • Added Session::rollback() to undo local changes and re-read the session data from storage
    • Added SessionTrainer for examining session changes unit testing
  • Released on 2023-08-20 2.0.0 on GitHub

    amphp/redis 2.0.0

    Initial release compatible with AMPHP v3. As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType> have been replaced with ResolutionType.

    • Added RedisParcel in the Sync sub-namespace implementing the Parcel interface from amphp/sync
    • Added RedisConnector interface to decouple connecting and init commands such as AUTH and SELECT
    • Reorganized class names / namespaces for better overview
      • Redis moved to RedisClient
      • Subscriber / Subscription moved to RedisSubscriber / RedisSubscription
      • Cache moved to RedisCache
      • Mutex sub-namespace has been changed to Sync. All classes within now have a prefix of Redis, e.g., MutexRedisMutex, MutexOptionsRedisMutexOptions
      • Config moved to RedisConfig
      • RespSocket moved to Amp\Redis\Connection\RedisConnection and is an interface now
      • RespParser moved to Amp\Redis\Protocol\RespParser
      • QueryExecutor moved to Amp\Redis\Connection\RedisLink
      • RemoteExecutor moved to Amp\Redis\Connection\ReconnectingRedisLink
      • RedisHyperLogLog moved to Amp\Redis\Command\RedisHyperLogLog
      • RedisList moved to Amp\Redis\Command\RedisList
      • RedisMap moved to Amp\Redis\Command\RedisMap
      • RedisSet moved to Amp\Redis\Command\RedisSet
      • RedisSortedSet moved to Amp\Redis\Command\RedisSortedSet
      • SortOptions moved to Amp\Redis\Command\Option\SortOptions
      • SetOptions moved to Amp\Redis\Command\Option\SetOptions
      • SocketException moved to Amp\Redis\Connection/RedisConnectionException
      • ParserException moved to Amp\Redis\Protocol\ProtocolException
      • QueryException moved to Amp\Redis\Protocol\QueryException
    • RedisSubscription is now a simple PHP iterator now that Amp\Iterator is no longer necessary with fibers.
  • Released on 2023-08-20 2.0.0 on GitHub

    amphp/http-server-static-content 2.0.0

    This release is compatible with amphp/http-server@^3.

    • DocumentRoot now requires an instance of HttpServer and ErrorHandler to construct
    • Removed DocumentRoot::onStart() and DocumentRoot::onStop(), as it’s now internally registered
    • Removed support for ServerObserver, as it’s been removed from amphp/http-server
    • Added StaticResource to serve a single static file
  • Released on 2023-08-19 2.1.0 on GitHub

    amphp/sync 2.1.0

    What’s Changed

    • Added re-entry support to synchronized() by @kelunik in https://github.com/amphp/sync/pull/26
    • Fixed error handling in SharedMemoryParcel
    • Fixed a typo by @thgs in https://github.com/amphp/sync/pull/25

    New Contributors

    • @thgs made their first contribution in https://github.com/amphp/sync/pull/25

    Full Changelog: https://github.com/amphp/sync/compare/v2.0.0…v2.1.0

  • Released on 2023-08-05 2.0.0 on GitHub

    amphp/http-server-router 2.0.0

    This release is compatible with amphp/http-server@^3.

    • A PSR-3 logger is now required in the Router constructor
    • Starting the server with an empty Router is now allowed and only logs a notice instead of throwing an exception
    • Middleware can be added via addMiddleware() instead of stack()
    • Removed support for adding middleware directly via addRoute(), use stackMiddleware() instead if you need this
    • Removed Router::onStart(), as it’s now internally registered
    • Removed support for ServerObserver, as it’s been removed from amphp/http-server
  • Released on 2023-08-05 2.0.0 on GitHub

    amphp/log 2.0.0

    • Increased minimum PHP version to 8.1
    • Make use of fibers with Amp v3 and Revolt
    • Added support for Monolog v3.x

    This release does not contain any changes in comparison to v2.0.0-beta.2.

  • Released on 2023-01-09 2.0.0 on GitHub

    amphp/cache 2.0.0

    Stable release compatible with AMPHP v3 and fibers! 🎉

    As with other libraries compatible with AMPHP v3, most cases of parameters or returns of Promise<ResolutionType> have been replaced with ResolutionType.

    • Renamed ArrayCache to LocalCache, swapping the constructor argument order
    • Modified LocalCache to implement IteratorAggregate and Countable, acting as an LRU cache now (#20)
    • Support arbitrary values in LocalCache, NullCache, and PrefixCache
    • Changed Cache to support arbitrary values
    • Introduced separate StringCache interface for caching only strings
    • Added StringCacheAdapter to use any Cache in place of a StringCache
    • Removed FileCache (will be available in amphp/file instead)
  • Released on 2023-01-07 1.4.5 on GitHub

    amphp/postgres 1.4.5

    • Fixed cancelling an active query if a connection is closed when using ext-pgsql (#54)
  • Released on 2023-01-06 1.1.4 on GitHub

    amphp/sql-common 1.1.4

    • Fixed potential double deferred resolve when a connection pool is full.
  • Released on 2022-12-30 1.1.0 on GitHub

    amphp/parser 1.1.0

    • PHP 7.4 now required
    • Improved performance of the parser when requesting small chunks of data and when yielding an integer length delimiter
  • Released on 2022-12-18 1.0.2 on GitHub

    amphp/sql 1.0.2

    • Fix a deprecation notice on PHP 8.1 if a configuration key does not have a value.
  • Released on 2022-12-18 3.0.0 on GitHub

    amphp/phpunit-util 3.0.0

    This package has been redesigned for compatibility with AMPHP v3 and fibers. AsyncTestCase serves a similar purpose as before, providing helper methods for unit testing within an async context. Each test case is run within a unique fiber to allow suspending during the test run.

    • AsyncTestCase::setUpAsync() and tearDownAsync() have been removed. Use AsyncTestCase::setUp() and tearDown() instead, as both of these methods are now able to execute async using fibers.
    • AsyncTestCase::createCallback() now returns a Closure. Additionally, an optional parameter for expected arguments upon invocation have been added (uses InvocationMocker::with(...) to set expected arguments).
  • Released on 2022-12-18 3.0.0 on GitHub

    amphp/amp 3.0.0

    Event Loop

    Amp no longer ships its own event loop. It’s now based on Revolt. Revolt\EventLoop is quite similar to Amp’s previous Amp\Loop. A very important difference is using float $seconds instead of int $milliseconds for timers though!

    Promises

    Future is a replacement for the previous Promise. There’s no need for callbacks or yield anymore! Its await() method is based on fibers and replaces generator based coroutines / Amp\Promise\wait().

    • Renamed Amp\Deferred to Amp\DeferredFuture.
    • Removed Amp\Promise\wait(): Use Amp\Future::await() instead, which can be called in any (nested) context unlike before.
    • Removed Amp\call(): Remove the passed closure boilerplate and all yield keywords, interruption is handled via fibers now instead of generator coroutines.
    • Removed Amp\asyncCall(): Replace invocations with Amp\async(), which starts a new fiber instead of using generators.
    • Removed Amp\coroutine(): There’s no direct replacement.
    • Removed Amp\asyncCoroutine(): There’s no direct replacement.
    • Removed Amp\Promise\timeout(): Future::await() accepts an optional Cancellation, which can be used as a replacement.
    • Removed Amp\Promise\rethrow(): Unhandled errors are now automatically thrown into the event loop, so there’s no need for that function anymore.
    • Unhandled errors can be ignored using Future::ignore() if needed, but should usually be handled in some way.
    • Removed Amp\Promise\wrap(): Use Future::finally() instead.
    • Renamed Amp\getCurrentTime() to Amp\now() returning the time in seconds instead of milliseconds.
    • Changed Amp\delay() to accept the delay in seconds now instead of milliseconds.
    • Added Amp\weakClosure() to allow a class to hold a self-referencing Closure without creating a circular reference that prevents automatic garbage collection.
    • Added Amp\trapSignal() to await one or multiple signals.

    Promise Combinators

    Promise combinators have been renamed:

    • Amp\Promise\race() has been renamed to Amp\Future\awaitFirst()
    • Amp\Promise\first() has been renamed to Amp\Future\awaitAny()
    • Amp\Promise\some() has been renamed to Amp\Future\awaitAnyN()
    • Amp\Promise\any() has been renamed to Amp\Future\awaitAll()
    • Amp\Promise\all() has been renamed to Amp\Future\await()

    CancellationToken

    • CancellationToken has been renamed to Cancellation.
    • CancellationTokenSource has been renamed to DeferredCancellation.
    • NullCancellationToken has been renamed to NullCancellation.
    • TimeoutCancellationToken has been renamed to TimeoutCancellation.
    • CombinedCancellationToken has been renamed to CompositeCancellation.
    • SignalCancellation has been added.

    Iterators

    Iterators have been removed from amphp/amp as normal PHP iterators can be used with fibers now and there’s no need for a separate API. However, there’s still some need for concurrent iterators, which is covered by the new amphp/pipeline library now.

    Closable

    Amp\Closable has been added as a new basic interface for closable resources such as streams or sockets.

    Strict Types

    Strict types now declared in all library files. This will affect callbacks invoked within this library’s code which use scalar types as parameters. Functions used with Amp\async() are the most likely to be affected by this change — these functions will now be invoked within a strict-types context.

  • Released on 2022-02-02 1.0.0 on GitHub

    amphp/rpc 1.0.0

    Initial release.

  • Released on 2021-12-14 1.0.1 on GitHub

    amphp/cluster 1.0.1

    Update to use amphp/file v2.x.

  • Released on 2021-12-05 2.1.2 on GitHub

    amphp/mysql 2.1.2

    • Fixed a bug when decoding a JSON field (#113)
  • Released on 2020-11-18 0.3.2 on GitHub

    amphp/beanstalk 0.3.2

    • Added support for Symfony YAML library v4 and v5. (#34)
  • Released on 2020-03-28 1.0.0 on GitHub

    amphp/serialization 1.0.0

    Initial release.

  • Released on 2019-12-31 1.0.0 on GitHub

    amphp/http-tunnel 1.0.0

    Initial release.

  • Released on 2019-12-21 1.0.0 on GitHub

    amphp/http-client-cache 1.0.0

    Initial release.

  • Released on 2019-11-04 2.1.0 on GitHub

    amphp/react-adapter 2.1.0

    • React\EventLoop\Factory is now automatically replaced with another implementation that throws on each usage to prevent two loops existing concurrently by accident. Set AMP_REACT_ADAPTER_DISABLE_FACTORY_OVERRIDE=1 as environment variable or constant to disable this protection.
  • Released on 2018-03-07 0.1.0 on GitHub

    amphp/react-stream-adapter 0.1.0

    Initial release.