Download the PHP package ziming/laravel-cloudflare-workers-kv without Composer

On this page you can find all versions of the php package ziming/laravel-cloudflare-workers-kv. 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 laravel-cloudflare-workers-kv

Laravel package for Cloudflare Workers KV

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Use Cloudflare Workers KV as a Laravel cache store or as a small key/value client. Values can be stored with Laravel-compatible PHP serialization or as plain JSON for easy reads from other Cloudflare Workers.

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Add your Cloudflare credentials to .env:

Usage

Laravel cache store

Add a cache store to config/cache.php:

Then use it like any other Laravel cache store:

The default php serializer uses PHP serialize() and unserialize(), matching the behavior expected by Laravel applications storing arrays, objects, booleans, and numbers in cache.

JSON key/value pairs

Use the json serializer when other Cloudflare Workers should read the values directly:

That stores this raw KV value:

From a Worker, read it as ordinary JSON:

Multiple namespaces

Every value in config/cloudflare-workers-kv.php is a default that any cache store may override in config/cache.php, so a single app can target several KV namespaces:

A store may override account_id, namespace_id, api_token, base_url, timeout, connect_timeout, serializer, allowed_classes, prefix, and graceful. Overriding any of the first six gives that store its own HTTP client; otherwise it shares the global one. Omitted keys fall back to the global config, so existing single-store setups keep working.

Graceful reads

By default a KV outage (5xx / connection error) surfaces as a CloudflareKvException from reads. Set 'graceful' => true (globally or per store) to make reads fail open — a failed get()/many() returns a cache miss (null) instead of throwing:

This trades loud failures for availability. Note that failing open can let a KV outage unleash a thundering herd onto whatever the cache is protecting, so weigh it per workload.

Artisan commands

Laravel's built-in cache:clear --store=… and cache:forget … --store=… work as usual. This package adds a few KV-specific helpers (all accept --store= and fall back to the global config when it is omitted):

Direct client

You can also resolve the package client directly:

The client also exposes bulk helpers, which use Cloudflare's bulk REST endpoints (one request per batch instead of one request per key):

The same bulk endpoints back Cache::many(), Cache::putMany(), and Cache::flush() on the cache store, so flushing or warming many keys does not fan out into N HTTP calls.

Binary values and many(). Cloudflare's bulk-get endpoint returns values as text/JSON and cannot carry non-UTF-8 bytes, so a binary value (e.g. a php-serialized payload that contains raw binary strings) is silently dropped from a many() result even though the key exists. PHP serialize() of typical scalars/arrays is ASCII and unaffected, but if you store binary blobs use the json serializer or read them one at a time with get(), which streams the raw body and is binary-safe.

Caveats & consistency model

Cloudflare Workers KV is an eventually consistent, globally distributed store. Its characteristics differ from Redis/Memcached, so keep the following in mind before choosing it as your cache backend:

In short: KV is a great fit for read-heavy, geographically distributed caching, and a poor fit for locks, atomic counters, and anything needing strong consistency.

Security

When using the php serializer, cached values are restored with PHP's unserialize(). If the KV namespace is shared with, or writable by, untrusted parties, a malicious payload could trigger PHP object injection. Restrict which classes may be instantiated via the allowed_classes config option:

The json serializer does not call unserialize() and is not affected.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-cloudflare-workers-kv with dependencies

PHP Build Version
Package Version
Requires guzzlehttp/guzzle Version ^7.8
php Version ^8.4
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^13.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 ziming/laravel-cloudflare-workers-kv contains the following files

Loading the files please wait ...