Download the PHP package leinonen/php-dataloader without Composer

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

PHP DataLoader

Port of the Facebook's DataLoader to PHP. Async superpowers from ReactPHP.

DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

Build Status Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality SensioLabsInsight

Table of contents

Installation

Require this package, with Composer, in the root directory of your project.

Usage

To create a loader you must provide a batching function, an internal memoization cache and the global event loop from ReactPHP. To have better understanding what the ReactPHP event loop is and how it is used refer to it's documentation.

Then load individual values from the loader. DataLoader will coalesce all individual loads which occur within a single tick of the event loop and then call your batch function with all requested keys.

Calling the load function returns React\Promise\Promises. To have a better understanding how to use promises within PHP refer to the ReactPHP docs.

Batch Function

The batch loading function accepts an array of keys, and must return a Promise which resolves to an Array of values. There are a few other constraints:

For example, if your batch function was provided the Array of keys: [2, 9, 6, 1], and the batch loaded results were:

The loaded results are in a different order that we requested which is quite common with most of the relation dbs for example. Also result for key 6 is omitted which we can interpret as no value existing for that key.

To satisfy the constraints of the batch function we need to modify the results to be the same length as the Array of keys and re-order them to ensure each index aligns with the original keys:

Caching

DataLoader provides a memoization cache for all loads which occur in a single request to your application. After load() is called once with a given key, the resulting value is cached to eliminate redundant loads.

In addition to relieving load on your data storage, caching results per-request also creates fewer objects which may relieve memory pressure on your application:

DataLoader caching does not replace Redis, Memcache, or any other shared application-level cache. DataLoader is first and foremost a data loading mechanism, and its cache only serves the purpose of not repeatedly loading the same data in the context of a single request to your Application. To do this it utilizes the CacheMap given as a constructor argument.

This package provides a simple CacheMap (leinonen\DataLoader\CacheMap) implementation to be used with DataLoader. You can also use your custom CacheMap with various different cache algorithms by implementing the leinonen\DataLoader\CacheMapInterface.

Usage with common ORM's

Eloquent (Laravel)

ActiveRecord (Yii2)

API

load($key)

Loads a key, returning a Promise for the value represented by that key.

loadMany($keys)

Loads multiple keys, promising an array of values.

This is equivalent to the more verbose:

clear($key)

Clears the value at $key from the cache, if it exists.

clearAll()

Clears the entire cache.

prime($key, $value)

Primes the cache with the provided key and value. If the key already exists, no change is made. (To forcefully prime the cache, clear the key first with $loader->clear($key)->prime($key, $value).


All versions of php-dataloader with dependencies

PHP Build Version
Package Version
Requires react/promise Version ^2.7.1
react/event-loop Version ^1.1.1
php Version ^7.4.0|^8.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 leinonen/php-dataloader contains the following files

Loading the files please wait ....