Giter Club home page Giter Club logo

phpnotifier's Introduction

PHPNotifier

PHPNotifier - is a task scheduler. Allows you to schedule a task that will be executed at any time you wish.

Installation

add to your composer.json - "krydos/php-notifier": "*"

Usage

First of all you have to run a script that will be listening for new tasks and execute them when time came.

php ./vendor/bin/phpnotifier /absolute/path/to/db.file

or if you want to leave it working in background

nohup php ./vendor/bin/phpnotifier /absolute/path/to/db.file & >/dev/null 2>&1 &

Using nohup you can see log output in nohup.out file.

How to create new tasks:

use \PHPNotifier\PHPNotifier;

$scheduler = new PHPNotifier(PHPNotifier::FILE_METHOD, '/absolute/path/to/db.file');
$scheduler->scheduleTaskIn(10, 'echo', [
    'Hello world!'
    '>'
    'any_file'
]);  

This task will be executed in 10 seconds. Command that will be executed is echo Hello world! > any_file

Since sometimes you know exact time when you want to run a task and you don't want to calculate how many time is remaining there is another method exists - scheduleTaskAtTime with same signature.

use \PHPNotifier\PHPNotifier;

$scheduler = new PHPNotifier(PHPNotifier::FILE_METHOD, '/absolute/path/to/db.file');
$scheduler->scheduleTaskAtTime(1459382400, 'echo', [
    'Hello world!'
    '>'
    'any_file'
]);  

This method accepts unix timestamp as first argument. If you use DateTime PHP's object you can get this value by getTimestamp() method.

make sure that binary you're trying to execute is exists in your system

TODO

  • support Redis as task store method
  • support as many store methods as possible
  • ability to accept DateTime as first argument for scheduleTaskAtTime method
  • ability to accept any valid date string as first argument of scheduleTaskAtTime method
  • ability to schedule repeatable tasks

Contributing

There are no special rules. Just send a pull request or create an issue.

phpnotifier's People

Contributors

krydos avatar

Stargazers

sbrilenko avatar

Watchers

James Cloos avatar sbrilenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.