Download the PHP package rasuvaeff/context without Composer

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

rasuvaeff/context

Latest Stable Version Total Downloads Build Static analysis Psalm level PHP

Deadline, cancellation and request-scoped values for PHP

Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model.

Requirements

Installation

Usage

A Context is an immutable, read-only view passed down the call graph: a deadline, a cancellation signal and request-scoped values. The owner of a cancellable branch keeps the matching ContextController. Cancellation is cooperative: code checks the context between steps; nothing is interrupted mid-call.

Create and derive

A child deadline is never later than its parent's: withTimeout() and withDeadline() take the earlier of the two. A zero or negative timeout is an immediate deadline; an oversized one saturates at PHP_INT_MAX instead of overflowing.

Check

Deadlines use monotonic hrtime() and are observed lazily: the next assertActive(), remainingMs(), isTerminated() or isExpired() call discovers an expired deadline. If the deadline belongs to an ancestor, the ancestor and its whole subtree are terminated. A controller cancellation propagates to every descendant immediately.

Cancel and clean up

onTerminate() runs the listener once when the context terminates (immediately if it already has) and returns a closure that unregisters it. A terminated context detaches from its parent and releases its listeners, so a long-lived parent does not accumulate per-request children. Always cancel the controller you own in finally.

Queue workers

Create a context per message with the job's TTR as the deadline, check it between external calls and acknowledge only when the job completes:

Crossing a process boundary

Deadlines are monotonic nanoseconds of the current process and mean nothing elsewhere. Send the remaining budget and rebuild it on the other side:

Validate the incoming value (an integer in a bounded range) before trusting it. rasuvaeff/context-http implements this for PSR-15/PSR-18.

Testing

Inject a TimeSource to drive deadlines deterministically:

Public API

Class Description
Context Immutable view: background(), withCancel(), withTimeout(), withDeadline(), withValue(), value(), assertActive(), is*(), remainingMs(), deadlineNs(), onTerminate()
ContextController Owner handle: cancel(?Throwable $reason = null)
TimeSource Monotonic clock seam (nowNs(): int) for deterministic tests
HrTimeSource Production hrtime() implementation
TerminationCause Cancellation or deadline cause passed to listeners
ContextException Base context exception (RuntimeException)
ContextCancelledException Explicit cancellation detected by assertActive(); the reason is previous
ContextExpiredException Deadline expiration detected by assertActive(); deadlineNs(), optional previous

Security

Context values are request-scoped metadata, not a service locator; keys are class strings and a value must be an instance of its key. The package never interrupts a blocking syscall: transport adapters must map the remaining budget to their own timeouts or register an onTerminate() cleanup listener. A budget received from another process is untrusted input — validate and cap it before building a context from it.

Examples

See examples/ for runnable scripts. Examples are expected to execute without fatal errors and stay aligned with the documented public API.

Script Shows Needs server?
basic.php Derivation, request-scoped values and cancellation no

Development

No PHP/Composer on the host — run in Docker via the composer:2 image:

Or with Make:

make test-coverage and make mutation bootstrap pcov inside the composer:2 container because the base image has no coverage driver.

License

BSD-3-Clause


All versions of context with dependencies

PHP Build Version
Package Version
Requires php Version 8.3 - 8.5
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 rasuvaeff/context contains the following files

Loading the files please wait ...