Download the PHP package m6web/tornado without Composer

On this page you can find all versions of the php package m6web/tornado. 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 tornado

Tornado 🌪🐎

Build Status

A library for asynchronous programming in Php.

Tornado is composed of several interfaces to write asynchronous programs using generators. This library provides adapters for popular asynchronous frameworks (ReactPhp, Amp) and built-in adapters to understand how to write your own.

Installation

You can install it using Composer:

You will also have to install additional dependencies related to the adapter you choose for your EventLoop you may check our suggestions using Composer:

ℹ️ Tornado includes its own EventLoop adapter to ease quick testing, and to show how you could write your own EventLoop optimized for your use case, but keep in mind that ⚠️Tornado adapters are not yet production ready⚠️.

How to use it

You can find ready-to-use examples in examples directory, but here some detailed explanations about asynchronous programing, and Tornado principles.

Dealing with promises

The EventLoop is the engine in charge of executing all asynchronous functions. If one of those functions is waiting an asynchronous result (a Promise) the EventLoop is able to pause this function and to resume an other one ready to be executed.

When you get a yield it, letting the EventLoop deal internally with Php Generators.

⚠️ Remember that the return type can NOT be array here, even if we expect that json_decode will return an array. Since we are creating a Generator, the return type is by definition \Generator.

Asynchronous functions

As soon as your function needs to wait a Promise, it becomes by definition an asynchronous function. To execute it, you need to use EventLoop::async method. The returned Promise will be resolved with the value returned by your function.

⚠️ Keep in mind that's a bad practice to expose publicly a Generator. Your asynchronous functions should return a Promise and keep its Generator as an implementation detail, you could choose to return a Promise in an other manner (see dedicated examples).

Running the event loop

Now, you know that you have to create a generator to wait a Promise, and then call Promise… But how can we wait the first Promise? Actually, there is a second way to wait a Promise, a synchronous one: the EventLoop::wait method. It means that you should use it only once, to wait synchronously the resolution of a predefined goal. Internally, this function will run a loop to handle all events until your goal is reached (or an error occurred, see dedicated chapter).

Like with the yield keyword, the Promise, but remember that you should use it only once during execution.

Concurrency

To reveal the true power of asynchronous programming, we have to introduce concurrency in our program. If our goal is to send only one HTTP request and wait for it, there is no gain to deal with an asynchronous request. However, as soon as you have at least two goals to reach, asynchronous functions will improve your performances thanks to concurrency. To resolve several independent Promises, use Promise that will be resolved when all others are resolved.

It's important to note that it will be more efficient to use EventLoop::promiseAll instead of waiting each input Promise consecutively, because of concurrency. Each time that you have several promises to resolve, ask yourself if you could wait them concurrently, especially when you deal with loops (take a look to EventLoop::promiseForeach function and corresponding example).

Resolving your own promises

By design, you cannot resolve a promise by yourself, you will need a Deferred. It allows you to create a Promise and to resolve (or reject) it while not exposing these advanced controls.

Error management

A Promise is resolved in case of success, but it will be rejected with a Throwable in case of error. While waiting a EventLoop::wait an exception may be thrown, it's up to you to catch it or to let it propagate to the upper level. If you throw an exception in an asynchronous function, this will reject the associated Promise.

When using EventLoop::async, all exceptions thrown inside the generator will reject the returned Promise. In case of a background computing you may ignore this Promise and not yield nor wait it, but Tornado will still catch thrown exceptions to prevent to miss them. By design, an ignored rejected Promise will throw its exception during its destruction. It means that if you really want to ignore all exceptions (really?), you have to catch and ignore them explicitly in your code.

FAQ

Is Tornado related to the Tornado Python library?

No, even if these two libraries deal with asynchronous programming, they are absolutely not related. The name Tornado has been chosen in reference to the horse ridden by Zorro.

I :heart: your logo, who did it?

The Tornado logo has been designed by Cécile Moret.

Contributing

Running unit tests:

Running examples:

Running PhpStan (static analysis):

Check code style:

Fix code style:


All versions of tornado with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
psr/http-message Version ^1.0
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 m6web/tornado contains the following files

Loading the files please wait ....