1. Go to this page and download the library: Download overblog/dataloader-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
overblog / dataloader-php example snippets
use Overblog\DataLoader\DataLoader;
$myBatchGetUsers = function ($keys) { /* ... */ };
$promiseAdapter = new MyPromiseAdapter();
$userLoader = new DataLoader($myBatchGetUsers, $promiseAdapter);
$userLoader->load(1)
->then(function ($user) use ($userLoader) { return $userLoader->load($user->invitedByID); })
->then(function ($invitedBy) { echo "User 1 was invited by $invitedBy"; });
// Elsewhere in your application
$userLoader->load(2)
->then(function ($user) use ($userLoader) { return $userLoader->load($user->invitedByID); })
->then(function ($invitedBy) { echo "User 2 was invited by $invitedBy"; });
// Synchronously waits on the promise to complete, if not using EventLoop.
$userLoader->await(); // or `DataLoader::await()`
use Overblog\DataLoader\DataLoader;
// Request begins...
$userLoader = new DataLoader(...);
// And a value happens to be loaded (and cached).
$userLoader->load(4)->then(...);
// A mutation occurs, invalidating what might be in cache.
$sql = 'UPDATE users WHERE id=4 SET username="zuck"';
if (true === $conn->query($sql)) {
$userLoader->clear(4);
}
// Later the value load is loaded again so the mutated data appears.
$userLoader->load(4)->then(...);
// Request completes.
$userLoader->load(1)->then(null, function ($exception) {
if (/* determine if error is transient */) {
$userLoader->clear(1);
}
throw $exception;
});