Download the PHP package zlikavac32/alarm-scheduler without Composer

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

Alarm scheduler

Build Status

This library provides support for multiple SIGALRM handlers.

Table of contents

  1. Introduction
  2. Installation
  3. API
    1. AlarmHandler
    2. AlarmScheduler
    3. InterruptException
    4. InterruptAlarmHandler
    5. CatchThrowableAlarmHandler
  4. Usage
  5. Rule of thumb
  6. Examples

Introduction

As of PHP 7.1, async signals are supported through pcntl_async_signals() function. With that nice feature, pcntl_alarm() became more helpful than ever.

Only issue is, we can set one signal handler per process.

This library provides simple scheduler for SIGALRM and allows multiple targets to be scheduled with some arbitrary delay.

Installation

Recommended installation is through Composer.

API

Two interfaces are provided, one for alarm handler and the other for the alarm scheduler.

Do note that this library does not call pcntl_async_signals(true);. It's the responsibility of the library user to call it where they find it applicable.

AlarmHandler

Interface \Zlikavac32\AlarmScheduler\AlarmHandler is used to implement alarm handler. Method handle() will be called from the signal handler so check Rule of thumb for more info.

Current scheduler is passed into handle() to allow rescheduling of the handler (or scheduling a new one).

AlarmScheduler

Interface \Zlikavac32\AlarmScheduler\AlarmScheduler is used to implement alarm scheduler. Implementation should take control over SIGALRM handling.

Methods must be safe to be called from within the signal handler. Check Rule of thumb for more info.

InterruptException

Exception representing hard interrupt that must be respected by the scheduler implementation.

It can be thrown from the alarm handler in order to cause exception from the signal handler.

Users are not restricted to this exception for the hard interrupt as described in the Rule of thumb section.

InterruptAlarmHandler

Causes hard interrupt from alarm scheduler by throwing InterruptException

CatchThrowableAlarmHandler

Alarm handler that wraps any other alarm handler and catches any throwable caught from it is implemented in \Zlikavac32\AlarmScheduler\CatchThrowableAlarmHandler. What is caught is passed into \Zlikavac32\AlarmScheduler\ThrowableHandler. If the throwable handler throws anything, it's silently ignored.

Simple throwable handler that just ignores everything is provided through \Zlikavac32\AlarmScheduler\IgnoreThrowableHandler.

Usage

First create the scheduler (currently, only single implementation is provided).

When it's applicable to take over of SIGALRM handling, call

Method start() must be called before any additional use of scheduler methods.

Then implement some alarm handler.

Next, schedule alarm handler.

Now, this will not block. If script reaches end before handlers are triggered, it will exit without triggering them.

For testing purposes, we can sleep for a few seconds. We can also print current time.

Rule of thumb

If SIGALRM is not blocked, it can interrupt scheduler methods at any point. Scheduler implementations must be safe to be run from within the signal handler. In most cases that means blocking signal until scheduler method is to be finished, and then unblocking it. PHP VM takes care of the rest.

No exception, except \Zlikavac32\AlarmScheduler\InterruptException, should be thrown from the alarm handler. If exception is thrown, and scheduler implementation does not catch it (which is not the requirement), it could leave the scheduler in inconsistent state.

If custom async exception is a requirement, alternative is to use SIGUSR1 or SIGUSR2 to throw exception from a different stack frame. PHP VM will deffer signal handling until current handler finishes. That means it will not affect scheduler stack frame.

sleep() may not be safe to use with SIGALRM so check how your system handles sleeping before using this library.

Examples

Examples with code comments can be found in examples directory.


All versions of alarm-scheduler with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
ext-pcntl Version *
php-ds/php-ds Version ^1.2
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 zlikavac32/alarm-scheduler contains the following files

Loading the files please wait ....