Download the PHP package co/loop without Composer

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

Moebius\Loop

An event-loop API for writing asynchronous code in traditional PHP code, while also working seamlessly with common asynchronous frameworks like React or Amp.

Moebius Loop provides an elegant and consistent API for working with non-blocking I/O which works equally well in classic synchronous PHP code as with fully asynchronous frameworks like React or Amp.

Laravel example

Moebius\Loop can be used with most frameworks such as Laravel or Symfony. The only challenge with using asynchronous code with these frameworks, is that the framework will not wait for your promises to finish.

The solution is to use the Moebius\Loop::await($promise) function. As long as all the code that is asynchronous is written to use Moebius\Loop directly, or written for either React or Amp - then you can use Moebius\Loop to resolve the promise.

As you can see, it is easy to use asynchronous code within any framework.

API reference

Moebius\Loop::getTime()

Get the current event loop time. This is a time indicating a number of seconds from an arbitrary point in time.

Moebius\Loop::await(object $promise, float $timeout=null): mixed

Run the event loop until the promise resolves or the timeout is reached.

Moebius\Loop::run(Closure $shouldResumeFunc=null): void

Run the event loop until Moebius\Loop::stop() is called. If a callback is provided, the loop will keep running until the callback returns a falsey value.

Moebius\Loop::delay(float $time, Closure $callback): Closure

Run the callback after $time seconds have passed. The returned callback will abort the timer.

Moebius\Loop::interval(float $interval, Closure $callback): Closure

Run the callback after $interval seconds have passed, and keep repeating the callback every $interval second. The returned callback will abort the interval.

Moebius\Loop::readable(resource $resource, Closure $callback): Closure

Run the callback on every tick as long as reading from the stream resource will not block. This can also be used to accept new connections on a server socket. The returned callback will abort watching the stream.

Moebius\Loop::writable(resource $resource, Closure $callback): Closure

Run the callback on every tick as long as writing to the stream resource will not block. The returned callback will abort watching the stream.

Moebius\Loop::read(resource $resource, Closure $callback): Closure

Read a chunk of data from the stream resource and call the $callback with the chunk of data that was read. This function will stop as soon as EOF is called, unless the returned callback is called to abort the read operation first.

Moebius\Loop::signal(int $signalNumber, Closure $callback): Closure

Run the callback whenever a signal is received by the process. The callback will continue to be called every time the signal is received, until the returned callback is invoked.

Example

A primitive example to illustrate how to write asynchronous code with Moebius\Loop.

This code will run with both Amp and React, and if you are not using one of these in a more classic environment such as Laravel or Symfony.

The entire API

Moebius\Loop::defer(callable $callback) will schedule callback to be executed next.

Moebius\Loop::queueMicrotask(callable $callback) will schedule a callback to be executed as soon as possible - before any deferred callbacks.

Moebius\Loop::delay(float $time, callable $callback): EventHandle will schedule a callback to be executed later.

Moebius\Loop::readable(resource $fd, callable $callback): EventHandle will schedule a callback to be executed whenever $fd becomes readable.

Moebius\Loop::writable(resource $fd, callable $callback): EventHandle will schedule a callback to be executed whenever $fd becomes writable.

Moebius\Loop::signal(int $signum, callable $callback): EventHandle will schedule a callback to be executed whenever the application receives a signal.

Moebius\Loop::run(callable $keepRunningFunc=null): void will run the event loop until the $keepRunningFunc returns false or the event loop is empty.

EventHandle class

When subscribing to events (IO, timer, interval or signal) you will receive an EventHandle class. This handle can be used to suspend or cancel the event listener.

Example:


All versions of loop with dependencies

PHP Build Version
Package Version
Requires moebius/promise Version >=1.0.100
composer/semver Version ^3.3
charm/fallback-logger Version ^1.0
moebius/common Version ^1.0
charm/util-closuretool 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 co/loop contains the following files

Loading the files please wait ....