Download the PHP package caronc/dateblock without Composer

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

Paypal PyPI Python npm Node.js Packagist PHP

Dateblock

Dateblock allows you to block (exactly how a Linux/Unix Cron might) until a specific point of time unlike 'sleep' which blocks for a set period of time. The difference is very subtle but can prove to be very useful.

It offers a few new features that the Internet Systems Consortium (ICS) version does not (refering to /etc/crontab style). Dateblock specifically offers the ability to wake/unblock on a specific second and/or drift a number of seconds after (or before) your calculated time is met (kind of like combining sleep and ICS Cron into one).

Python, PHP and Node.js bindings are additionally included, supporting the standard date and time objects of each language!

Quick Start

The dateblock command is a C++ tool; install it from the distribution packages or build it from source (see Installation).

The Python library is on PyPI (Linux, macOS and Windows):

The PHP extension installs with PIE (Linux and macOS with a 64-bit time_t, PHP 8.0 and newer):

The Node.js package is on npm (Node.js 20 and newer, on a system with a 64-bit time_t):

Packages for Fedora, RHEL/CentOS/Alma/Rocky 9 and 10, Debian and Arch Linux can be built from this repository; see Installation.

Syntax: dateblock [options] [--] [command [arguments...]]

Allowed options:

A variety of syntax is accepted by this tool such as:

Note: With the exception of the drift option (+ or -), all variations of the syntax mentioned above can be mixed if separated using the 'comma' (Separator) operator. ie: /a,b,c-d,/e is valid. However: x-y-z is not valid, nor is /x/y, /x-y or a '' mixed with other entries (ie: *,5). All values must be within the range of it's time type. Thus 400-4000 would never work since no time constraint even resides within that range.

The --cron(-c) switch allows one to specify the standard cron formatting:

Substitute an asterisk (*) as a placeholder for arguments you are not interested in. Asterisks are automatically placed in strings missing all 6 arguments (separated by white space).

The crontab shortcuts work too (with or without --isc). Without --isc one can be followed by a drift (ie: @daily +30 or @daily -30):

The --isc (-i) switch makes the cron interpretation equivalent to what it is today (ISC stands for Internet Systems Consortium). Hence:

The --test(-t) switch is your greatest ally. Use this to simply build and test your crons to find out when they would have blocked until without actually blocking. If you pair the the test with the --ics (-i), then you can use this tool to help construct regular crons for /etc/crontab if you're new to the idea and still learning how the crontabs work.

Timezones:

The schedule is read in this computer's timezone unless --timezone (-z) names another one from the timezone database (such as America/Toronto or Asia/Tokyo). Daylight saving follows that timezone, and dateblock unblocks at that exact moment no matter where the computer is. The times shown by --test and --verbose are in that timezone too.

Listing the next few times:

--count (-C) lists the next few times a schedule matches, without waiting. It is the quickest way to check a schedule, and with --isc (-i) a handy way to learn how a crontab entry behaves:

Running a command:

Put a command (and its arguments) after the options, and dateblock runs it once the time is reached:

To run it again and again, put dateblock in a loop:

Drifting:

Drifting is an option that allows you to adjust the calculated results by some additional time. Lets say you wanted the application to wake up on the 1st minute of each 10 min interval (1, 11, 21, 31, 41, 51). Specifying the cron (minute) '/1' would not work. In fact the cron of '/1' would unblock at every minute. You could however achieve the previous example using a drift value of '60' (seconds) and a cron (minute) entry of '*/10'.

In a way, drifting is a little like executing a cron and then sleeping for an additional period right afterwards (a negative drift wakes up that much sooner instead). However this is a much more elegant solution with a more precise blocking period.

Some things to consider about drifting:

Examples

The following would block until a minute divisible by 10 was reached. Minutes divisible by 10 are: 0,10,20,30,40 and 50.

The following would block until a second is divisible by 5 was reached and only on hours 3 and 4. This can also be written as such:

The following would block until the 5 minute of every hour:

The following would block until a hour divisible by 5 was reached on the first half of the month as well as the 20th of the month) Hours divisible by 5 are: 0, 5,10,15 and 20.

Drifting using the cron was added in v1.0.0 (but was always available using -x or --drift). The advantage you get from using it inline with the cron string is the ability to chain them with multiple drift times using a comma and or range operator. The modulus one will not work here.

The following will block until the 5:20 minute mark of each hour (20 seconds past)

The expression is considered invalid if more entries are found after the drift period. However this is still valid:

A negative drift wakes up early; this blocks until 4:40 past each hour (20 seconds before the 5 minute mark):

DateBlock Python Bindings

The DateBlock python bindings are really easy to use too:

A few things worth knowing:

With asyncio, use await dateblock.wait(...) instead. It takes the same cron, ref and isc arguments, returns the same datetime, and lets your other tasks keep running while it waits (no thread needed):

To see the next few times without waiting, use dateblock.upcoming(). It takes the same cron, ref and isc, plus a count (just the next one unless given, at most 1000), and returns a tuple of datetimes, earliest first:

DateBlock PHP Bindings

The PHP extension adds a dateblock() function that works the same way (and dateblock_upcoming(), below):

A few things worth knowing:

dateblock_upcoming() lists the next few times without waiting. It takes the same $cron, $ref and $isc, plus a $count (just the next one unless given, at most 1000), and returns an array of DateTimeImmutable, earliest first, in the same timezone dateblock() would use:

The array is shorter than $count only when no later time exists. The limits are in DATEBLOCK_COUNT_DEFAULT and DATEBLOCK_COUNT_MAX.

DateBlock Node.js Bindings

The Node.js package waits without blocking: dateblock() returns a promise, and the rest of your program keeps running in the meantime.

A few things worth knowing:

Installation

From PyPI (the Python library)

This gives you the Python library on Linux, macOS and Windows (the C++ code is compiled straight into it, so nothing else is needed). The dateblock command is the C++ tool; install it from the packages or build it from source as shown below.

With PIE (the PHP extension)

PIE builds the extension on your computer (the C++ code is compiled straight into it), so it needs a C++ compiler and the PHP development files (ie: php-devel or php-dev), and then turns it on (or tells you how).

Like the rest of dateblock, it needs a 64-bit time_t: every 64-bit system has one, and so does current 32-bit ARM Linux. Older 32-bit systems can't hold dates past 2038, so the build stops there with an error (see INSTALL.md).

From npm (the Node.js package)

It comes ready built for Linux (x64 and arm64, including Alpine), macOS (Intel and Apple silicon) and Windows (x64 and arm64): npm installs the one for your computer, so nothing is compiled and there is no install step to approve. Anywhere else, build it once after installing (this needs a C++ compiler and Python; see node-gyp); the error you get without it says so too:

It needs a 64-bit time_t too, so it won't build on older 32-bit systems (see INSTALL.md).

From Source

Assuming you have a C++ compiler and the standard development tools that usually go with it (make, autoconf, automake and libtool), then the following will install everything for you.

This installs:

To build the Python bindings from your checkout (this compiles the C++ code straight into the Python module):

To build the PHP extension from your checkout (it needs the PHP development files; the C++ code is compiled straight into it unless you add --with-libdateblock to use the installed library instead):

Then turn it on by adding extension=dateblock to your php.ini (or a new file in its conf.d/ directory).

Building with Docker

Don't want to install the build tools? If you have Docker (or Podman) and GNU make, you can build and test everything inside a container straight from a fresh checkout; no ./configure needed:

See packaging/README.md for the details on each package format, and INSTALL.md for building from source.


All versions of dateblock with dependencies

PHP Build Version
Package Version
Requires php Version >=8.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 caronc/dateblock contains the following files

Loading the files please wait ...