PHPackages                             steadweb/nyx - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. steadweb/nyx

ActiveLibrary[CLI &amp; Console](/categories/cli)

steadweb/nyx
============

PHP process manager of the night.

0.1.3(9y ago)413[7 issues](https://github.com/steadweb/nyx/issues)MITPHPPHP &gt;=5.3

Since Feb 11Pushed 9y ago3 watchersCompare

[ Source](https://github.com/steadweb/nyx)[ Packagist](https://packagist.org/packages/steadweb/nyx)[ RSS](/packages/steadweb-nyx/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Nyx
===

[](#nyx)

[![Build Status](https://camo.githubusercontent.com/cbe2702ba69201fc9af1b5d4198838d89415e8b94c79beb657588bf7e1c31a29/68747470733a2f2f7472617669732d63692e6f72672f73746561647765622f6e79782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/steadweb/nyx)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7bc52fd3e82cf8b5dcdc31895cb5aaa1d0ae150413d05f089a24a09cfb80cf5c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73746561647765622f6e79782f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/steadweb/nyx/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0336c40c6a8390f948ef58ac9efbe649b5039a43aae09a527f8ae1771f5e0962/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73746561647765622f6e79782f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/steadweb/nyx/?branch=master)

A lighweight PHP process manager.

Nyx is a worker process manager which aims to provide functionality to run multiple workers based on configuration. The idea of Nyx replaces the need to run multiple windows / screens / commands within the termnial when instantiating workers.

A better example of Nyx would be to use Supervisor.d which is heavily supported and maintained. Nyx is a lightweight alternative written in PHP.

### Example

[](#example)

Let's assume the scripts below are long-running process workers that need to be run from the command line. Multiple termnials (or linux screens) would be created to achieve this.

```
$ php /path/to/worker1.php
$ php /path/to/worker2.php

```

Nyx tries to eliminate this by allowing you to confgure the amount of workers you want to run, thus running one command.

```
php nyx.phar run /path/to/nyux-config.json

```

Getting started
---------------

[](#getting-started)

Download the latest .phar from

```
wget https://steadweb.github.io/nyx/nyx.phar

```

Or install using composer

```
composer require steadweb/nyx ~0.1

```

Configuration
-------------

[](#configuration)

Using `nyx.phar` requires you to provide the location of your `nyx.json`. The configuration files suggests where your workers are located, how many workers the manager should spawn and whether to log the outout / errors to file.

Example.

```
{
  "workers": [
    {
      "count": "1",
      "path": "ping 8.8.8.8",
      "options": {
        "in": {
          "type": "pipe",
          "command": "r"
        },
        "out": {
          "type": "file",
          "command": "/tmp/google-ping.log",
          "options": "a"
        },
        "err": {
          "type": "file",
          "command": "/tmp/google-ping-error.log",
          "options": "a"
        }
      }
    },
    {
      "count": "1",
      "path": "ping 8.8.4.4"
    },
    {
      "path": "php foo.php"
    }
  ]
}

```

This sample configuration will create three pools, each with one worker assigned. The first two pools will continue to ping their respective IPs `8.8.8.8` and `8.8.4.4`. We'll come back to the third pool later on.

Basic usage
-----------

[](#basic-usage)

Once you've created your `nyx.json` run the following command:

`php nyx.phar run /path/to/nyx.json`

And you should see the following output:

```
[*] Current PID: XXX
[+] Starting worker
[+] New process with command: php /path/to/worker/foo.php
[*] Workers started
[*] Handler registered

```

### Notes

[](#notes)

- The current PID is the process ID of the nyx manager. At any given point you can track this using a process monitor, i.e. `top`, if using a linux / unix system.
- Each pool that's suggested within your config will tell you each time it creates a new worker and a new process.
- The handler registered log allows us to catch `SIGTERM` signals.

To exit the manager, simply press `CTRL + C` and all sub processes will exit along with the manager.

Working example: foo.php
------------------------

[](#working-example-foophp)

Our example configuration had three pools; two of those pools create one worker in each which would ping IPs. The third pool creates one worker which runs a PHP script, `foo.php`.

```
...
{
    "path": "php foo.php"
}

```

The example `foo.php` script is below. Take a look at the example, you'll notice the script ends after ~5 seconds.

### Code

[](#code)

```
