Download the PHP package krypt0nn/asynclib without Composer

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

🚀 Asynclib

Asynclib is a library that gives you ability to create asynchronous tasks in PHP 7.4+

Installation

About asynchronous programming

* yellows is a tasks ran asynchronously

This diagram shows the difference between synchronous and asynchronous programs. First ones executing every task in the main process so if you have a task like get a huge file from a website - the program will be paused (lagged) until this task will be not finished. It also means that other tasks in your program will be executed only after this one

Asynchronous programs execute tasks parallel. In Asynclib, every new task runs in another process which means that they will not affect the main program and stop its execution. We can run long high weight tasks async and monitor their states from the main process which will give us a valuable performance boost

Basic usage

For practical example you can look at test directory

Also, keep in mind that this library was developed only for desktop usage. I didn't test it on websites and don't know will it works there or not

Every task should be written in its file. This file should return the TaskRunner object. For example:

Callable inside TaskRunner constructor takes 2 arguments: array $options and TaskRunner $task. The first is an array of parameters you give this task in Task->run method when the second is the current TaskRunner object

To run this task in your main code you should use Task class:

After that you TaskRunner will begin its work in another process so it will not affect your code in the current process, stop it, or something like that

Task object, which is now stored in our $task variable, has a lot of useful methods. But the major is update. This method will synchronize task state and process performed events

We can wait until task will be completed using another major method wait

This method has 3 arguments: ?int $milliseconds = null, int $delay = 100 and callable $callback = null. First is the amount of milliseconds after which this function will stop ints work. If you write here a null value - then this method will wait until the task will not be finished. The second argument defines delay between task state updates (update method calls). And the last argument is a callable that takes current Task object and runs after each task update. If this callable returns true (boolean value) - then the wait method will be stopped

Another useful part of Task objects is that you can give them an events. For example:

And perform this event from TaskRunner callable:

Event some_event will be performed when method update will be called

$data argument can be anything PHP can serialize with function serialize: string, number, boolean, array, object...

Task also has a special event which will be called when it will be done

Like Task, TaskRunner also has events with the same syntax. To receive events from Task (main process) and execute them - use TaskRunner->update method

To forcibly interrupt task execution you can call method stop

It also will set the task state as 0 (just initialized)

Other available methods:

Name Type Description
output sting Get task output if it is done
id string Get task id
pid int Get id of the process which executing this task
state int Get task state. 0 - just initialized, 1 - running, 2 - done
initialized bool Check if the task is just initialized
running bool Check if the task is running
done bool Check if the task is done

Tasks pools

You can unite some tasks into one pool and run them together

Method update will update states of all the tasks in this pool and remove the ones which are already finished. It also can take a callback which will be used for every unfinished task. updateWhileExist is something similar to wait in Task, but works like update: takes a callable and runs it for every unfinished task until there will be unfinished tasks

You can get tasks outputs with method output

This method will throw an exception if provided task id does not exist or this task is not finished yet

Also, you can use outputOrNull method if you don't want to work with exceptions. Null value will be returned when the task is not finished or is not exists

Method add can add a new task to the pool

Known issues and todos


Author: Nikita Podvirnyy


All versions of asynclib with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
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 krypt0nn/asynclib contains the following files

Loading the files please wait ....