Download the PHP package perry-rylance/split-batch without Composer

On this page you can find all versions of the php package perry-rylance/split-batch. 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 split-batch

Split Batch

This library provides a means to do large batch processing when unix cron jobs aren't necessarily available.

This is useful when you need to process a large amount of data, or carry out a time consuming task, where cron isn't available, such as on low tiered shared hosting.

Overview

The library provides a base class for you to extend from which you can use to manage imitated cron jobs, or split batch jobs.

A base class is provided to define batch jobs.

A daemon is used to manage these jobs.

The daemon will run jobs. A single run will usually consist of multiple iterations.

The daemon times each run, records the number of iterations, and will manage the frequency at which the job runs, limit iterations where needed, and limit the elapsed time for any given run. A run will terminate when either the maximum iterations per run is reached, or, the maximum period in milliseconds has elapsed.

Requirements

Requirements (Testing)

The test file enclosed calculates the first 50,000 prime numbers, and fills a CSV out with this data in the databases memory. Once this has been completed the result will be written to disk. This is a large amount of data, and will need a higher packet size.

In practical applications, it's recommended that you implement a strategy for working with file pointers or similar, rather than working with the entire dataset in your jobs state.

Requirements (Building)

Installation

I recommend using Composer to install this package.

Extensibility

These instructions assume that you are using WordPress, which is presently the only supported framework.

The library uses Doctrine for database interaction. There is potential to expand on the Connection class in this library to add more integrations, any database which Doctrine can connect to can be used with this library.

Usage

Please see the example in test.php for step by step implementation instructions.

Database connectivity

This library uses Doctrine for database interaction and can potentially be compatible with any database which Doctrine can work with.

Connection::$instance must hold an instance of \Doctrine\DBAL\Connection in order for the library to function.

A convenience function is provided for working in a WordPress environment:

\PerryRylance\SplitBatch\Connection::fromWordPress() will initialise Connection::$instance based on the constants (and table prefix) defined in wp-config.php. Therefore, this connection must be set up after WordPress' config file has loaded.

Starting the daemon

This library uses a daemon which oversees setting up the database tables and actually running jobs.

After setting up your Connection, you need to instantiate the daemon.

$daemon = new \PerryRylance\SplitBatch\Daemon();

The daemon will initialise the database tables if necessary.

Defining a Job

  1. Subclass \PerryRylance\SplitBatch\Job to start working with the library.
  2. You need to implement the abstract function init on your subclass of Job.
    • Setting frequency (milliseconds) on your Job adjusts the minimum number of milliseconds before a Job can be run again.
    • Setting max_iterations on your Job adjust the maximum number of iterations a Job is allowed to do in one run.
    • Setting max_period on your Job defines a time limit for the run.
    • The state property on your Job is where you need to hold the state of your iterator, for instance, which row of a spreadsheet you are presently working with, a byte cursor representing a file pointer, or anything else you need to keep track of the state of any given job.
  3. You need to implement the abstract function iterate on your subclass of Job. This function is where the work will be done.
    • Your iteration function should call success or abort once is has reached a completed state, whether it completed successfully or failed.
    • Your iteration function should return false if it wants iteration to stop. This can be used in conjunction with the above, or, it can be used to cease iteration without destroying the job when you want to stop iterating for the current run based on some kind of custom condition.
    • Once a job completes, whether successful or aborted, the job will be removed from the database. You can override success, abort or complete to take any actions you need at this point (for example, logging).

Instantiating your Job

  1. Use the static method Job::create to create an instance of your job. You must pass the fully qualified class name of your job, followed by a handle which will be used to uniquely identify this instance of the job.
    • If a job with this handle doesn't exist already, it will be created and init will be called on the job.
    • If a job with this handle already exists, the instance data will be loaded from the database, the class will be instantiated and you'll receive the existing job from the database. This isn't usually necessary, but is provided as a convenience. It's recommended that you implement all logic within your subclass itself rather than working on the object externally.

Running the daemon

  1. Call $daemon->run(); on the daemon you previously created. The daemon will run all applicable jobs, managing limiting iteration, timing and scheduling along the way.

Running the example

If you would like to run the example included with this library, please have a valid WordPress installation set up with your web server serving it up.

Extract or clone this repository into a subfolder one level below your web root, then visit /SplitBatch/test.php on your server.

The test will read an input CSV which currently contains 50,000 rows. It will then start figuring out the n-th prime number for each row.

The test script will reload itself every 1 second to trigger another iteration until the job has completed and all 50,000 primes have been found.

At this point the result is written to test-result.csv and downloaded by the browser.

Depending on the performance of the server this is run on, you'll probably see a high number of iterations (up to 10,000) at first, possibly completing before the self imposed 1,000ms default limit on execution time.

As the job progresses, you'll likely see that the 1,000ms limit is being hit with below 10,000 iterations completing. Because of the nature of the algorithm used to find primes in this example, this will get progressively slower until the job completes.


All versions of split-batch with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
doctrine/dbal Version ^3.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 perry-rylance/split-batch contains the following files

Loading the files please wait ....