Download the PHP package phpgt/promise without Composer

On this page you can find all versions of the php package phpgt/promise. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package promise

A pleasant way to work with asynchronous PHP.

There are many implementations of the concept of a Promise. This library aims to be compatible with the Web API's Promise implementation, providing a then, catch and finally mechanism that behave the same as when working with promises in the web browser.


Build status

Code quality

Code coverage

Current version

PHP.Gt/Promise documentation

In computer science, a Promise is a mechanism that provides a simple and direct relationship between procedural code and asynchronous callbacks. Functions within procedural languages, like plain old PHP, have two ways they can affect your program's flow: either by returning values or throwing exceptions.

When working with functions that execute asynchronously, we can't return values because they might not be ready yet, and we can't throw exceptions because that's a procedural concept (where should we catch them?). That's where promises come in: instead of returning a value or throwing an exception, your functions can return a Promise, which is an object that can be fulfilled with a value, or rejected with an exception, but not necessarily at the point that they are returned.

With this concept, the actual work that calculates or loads the value required by your code can be deferred to a task that executes asynchronously. Behind the scenes of PHP.Gt/Promise is a Deferred class that is used for exactly this.

Example usage

The following is an example of the syntax provided by this library.

Deferred and Promise objects

This repository splits the responsibility of the asynchronous task's processing and the result of the task completion into the Deferred and Promise classes respectively.

A Deferred object is assigned one or more "process" callbacks, which will be called in order to execute the deferred task.

A Promise is created by the Deferred upon construction, which is used to represent the result of the deferred task's completion.

To make a class work with promises, it needs at least two functions: one public function that constructs the Deferred object and returns the Promise, and one function that is assigned as the Deferred's process function.

See the example code layout below:

The simplest representation of how the above Example class would be integrated is as follows:

The end result is the ability to call the public function, without needing to know anything about Promise/Deferred implementation.

Important: PHP is still a fully procedural language, so without an external loop being used to call the deferred process, the promise will never fulfil or reject.

Event loop

In order for this Promise library to be useful, some code has got to act as an event loop to call the deferred processes. This could be a simple while loop, but for real world tasks a more comprehensive loop system should be used.

The implementation of a Promise-based architecture is complex enough on its own, so the responsibility of an event loop library is maintained separately in PHP.Gt/Async.

Special thanks

The work put into the development of this repository is mainly thanks to the great work and inspiration given by reactphp's promise implementation and the superb writing of Domenic Denicola.


All versions of promise with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpgt/promise contains the following files

Loading the files please wait ....