Download the PHP package kohkimakimoto/workerphp without Composer
On this page you can find all versions of the php package kohkimakimoto/workerphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kohkimakimoto/workerphp
More information about kohkimakimoto/workerphp
Files in kohkimakimoto/workerphp
Package workerphp
Short Description A PHP micro job scheduler framework like cron.
License MIT
Homepage https://github.com/kohkimakimoto/workerphp
Informations about the package workerphp
WorkerPHP
A PHP micro job scheduler framework like cron.
Requirements
- PHP5.4 or later
- pcntl extension
Installation
Create composer.json
for installing via composer.
Run composer install command.
Usage
- Bootstrap
- Jobs
- Http Server (Web APIs)
- Service Providers
Bootstrap
To make a job scheduler application like cron, create worker.php
file (or other name you want).
You need to load composer autoload.php
file and create an instance of Kohkimakimoto\Worker\Worker
.
Run php worker.php
. You will get the following messages and the process keep in your system. But it is not useful at this time. Stop the process using CONTROL-C.
Learn about jobs at the next section.
Jobs
Define a job.
This $worker->job
method has two arguments. The first argument is name of job. It must be unique in all jobs.
The second argument is an array that has some parameters. cron_time
is a schedule when to run the job.
It is a "cron expressions" string. command
is a closure that is executed by the worker.
You can run it. You will get messages like the below.
The job you defined runs every minute.
Also you can define command
a command string not a closure.
The worker runs command uptime
every minute.
You can set a limit on running processes at the same time. Use max_processes
.
Http Server (Web APIs)
WorkerPHP has a built-in http server. It provides APIs that controls jobs using HTTP requests. Write the following code.
When WorkerPHP starts, It listens port 8080
(default).
You can modify listened port and host.
Get a worker info
If you started http server, you can get worker infomation using http request.
You will get below json.
Get a job info
You can get a job info by specifing job name.
You will get below json.
Run a job
You can run a job using POST request.
You will get below json.
Service Providers
ServiceProvider allow the user to extend WorkerPHP. Please see the built-in Service Provider StatsServiceProvider
.
Author
Kohki Makimoto [email protected]
License
MIT license.
All versions of workerphp with dependencies
ext-pcntl Version *
react/react Version 0.4.*
pimple/pimple Version ~3.0
symfony/event-dispatcher Version 2.6.*
symfony/console Version 2.6.*
symfony/process Version 2.6.*
symfony/finder Version 2.6.*
symfony/routing Version 2.6.*
mtdowling/cron-expression Version 1.0.*