Download the PHP package boruta/timebase without Composer

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

TimeBase

Tests Status

Flat file database for storage any data as events in timeline and finding it for a given timestamp.

Table of contents

  1. Description
  2. Requirements
  3. Installation
  4. Usage
    1. Quick introduction
    2. Details
      1. Extra logger in constructor
      2. Data types
      3. Setting the storage namespace
      4. Inserting data for specific timestamp
      5. Searching data for specific timestamp
      6. Getting multiple records with the same timestamp
      7. Searching strategies
  5. Tests

Description

The data are stored in files, with the possibility of using multi-level namespaces - in this case, the files are stored in subdirectories. Each day is stored in a separate file named YYYY-MM-DD.tb.

The data records are searched using a binary search algorithm, so it's quick and doesn't require loading the entire file into memory. Each record is one line in file, in format {timestamp}/{data} (data is result of base64_encode(json_encode(...))). The records are sorted, and you can add multiple records for one timestamp - they are saved and returned in the order they were added.

There are many use cases for such a database, e.g. storing stock exchange data (volumes, price values etc.) for trading strategy backtesting.

Requirements

Package requires PHP >= 7.3 and ext-json installed.

Installation

Install the library using Composer. Please read the Composer Documentation if you are unfamiliar with Composer or dependency managers in general.

Usage

Quick introduction

Creating database instance. First constructor argument is a path where to store database files.

Inserting data (for current timestamp) :

Getting last inserted data (last record):

You will get array as result, with keys timestamp and value:

Details

Extra logger in constructor

You can optionally give the second argument which is a logger object, compatible with Psr\Log\LoggerInterface. The application append logs only in case of errors.

Data types

The data can be of any native type, e.g. int, string, array. When searching for data, they will be of the same type.

Setting the storage namespace

You can store your data in different storages on many levels. Please use the method ->storage(array $storage) to set this.

Examples of inserting data into specific storage:

Examples of reading data from specific storage:

Inserting data for specific timestamp

To add data for a given timestamp (not the current) use the method ->timestamp(int $timestamp). Example:

Searching data for specific timestamp

To find a record for a specific timestamp use the method ->timestamp(int $timestamp) during search query:

In the default strategy, you will get one record that is closest to the timestamp you entered.

Getting multiple records with the same timestamp

If you have more than one record with the same timestamp you can retrieve them using the ->all() method.

In the result array there will be an additional key all containing all records for given timestamp, in the order in which they were added:

Searching strategies

Nearest (default)

The default strategy returns the record with the nearest timestamp to the given one. Usage (is not necessary as it is the default):

If the time distance is the same for two records, you will get the earlier one.

Exact

If there is no record for the timestamp you provided, you will get null value. There must be a record in the database with exactly the same timestamp.

Earlier

If there is no record for the timestamp you entered, you will get the closest one before that timestamp or null.

Later

If there is no record for the timestamp you entered, you will get the closest one after that timestamp or null.

Tests

To run the tests in the package, execute the following command:

After a while you will get the result, example:


All versions of timebase with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-json Version *
psr/log Version ^1.1
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 boruta/timebase contains the following files

Loading the files please wait ....