Download the PHP package choval/async without Composer

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

tests

Choval\Async

A library to ease handling promises in ReactPHP.

Install

Requirements

Usage

Having the following function

The ugly way:

Using yield, remember future() is returning a Promise.
And we're not blocking other events in the loop ;-)

Or in a while-loop

Functions

is_done

Checks if a Promise has been resolved or rejected. This returns a boolean, not a Promise.

resolve

This is what will let you yield promises, it's like Node.js await.

Take for example the following async events.

$promise resolves with hello world in 1 sec, despite the second promise resolving first.

What if you need to run multiple async simultaneously?

Memory usage

silent

Similar to resolve, but will catch any Exception and save it in the second parameter.
If it fails, the promise will resolve with null.

execute

Executes a command asynchronously.
Returns a Promise with the output of the command.

A timeout parameter (in seconds) can be passed.

sleep

An asynchronous sleep function. This won't block other events.

Remember this is a non-blocking sleep, if you do not wait for it or yield inside an Async\resolve, the Promise will solve in the background.

wait

Also knowsn as sync, makes asynchronous code blocking. Use this when you need to use an async library in a sync/blocking scenario.

This function receives one of the following: Generator, Closure or PromiseInterface.

A second float parameter is a timeout in seconds, defaults to no timeout.

A third float parameter is the interval at which to check, defaults to 0.01 secs. A low interval will consume much more CPU.

async

Have a piece of blocking code that you need to run in async? Use this, just keep in mind it is using pcntl_fork.

First parameter is a callable, second parameter is an array of parameters for the callable.

There's a limit of 50 simultaneously running async forks. This limit can be changed by calling Async\set_forks_limit.
This limit is counted for Async\execute as well.

When the limit is reached, the code will wait for any previous fork to finish before continuing, keeping a max of async forks at the set forks limit.

retry

Runs a function (Closure/Generator) up to retries times for a "good" return. Otherwise, returns the last Exception.
This function can also ignore a set of Exception classes or messages.

timeout

Similar to React\Promise\Timer\timeout(), but allows a Generator or Closure too.

timer

Saves the number of elapsed microseconds (float).

wait_memory

Waits for a number of memory bytes to be available.
This is used inside loops to avoid memory exhaution due to multiple Promises being created and left in background.

A second parameter can be passed for the frequency to run the check.
Returns the number of bytes remaining (memory_limit - memory_get_usage()).

rglob

A recursive glob with an ignore parameter.

Consider the following files:

PHP file functions

The following functions are available with the same parameters as their PHP versions, but run using Async\async and take an optional LoopInterface as their first parameter.

These are not production tested/optimized. Please use with caution.

Example:

License

MIT, see LICENSE.


All versions of async with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0|^8.1
react/promise-stream Version ^1.3
react/child-process Version ^0.6
react/promise Version ^2.8|^2.9
react/event-loop Version ^1.2|^1.3
choval/zombie-reaper 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 choval/async contains the following files

Loading the files please wait ....