PHPackages                             kore/njq - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. kore/njq

ActiveLibrary[Queues &amp; Workers](/categories/queues)

kore/njq
========

Native PHP Job Queue

533195PHP

Since Sep 15Pushed 8mo ago3 watchersCompare

[ Source](https://github.com/kore/njq)[ Packagist](https://packagist.org/packages/kore/njq)[ RSS](/packages/kore-njq/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

To make use of multiple cores for some rather long processing operations I needed a way to fork multiple workers from a single PHP script multiple times lately. So I created this small project which implements this in a way, so that it should reusable by anybody.

Native job queue
----------------

[](#native-job-queue)

The implementation and usage is pretty simple. There is in an interface `JobProvider` which has the methods `hasJobs()` and `getNextJob()`, which you need to implement. The second method should return valid PHP callbacks - for example Closures. Those are then executed (in parallel) by the executor.

I also implemented a `ShellJobProvider` (which implements `JobProvider`), which is constructed from an array of shell commands, which then are executed in parallel. A simple working example:

```

```

The file `test` will then contain something like (the order might vary):

```
5
4
3
2
1
```

The `4` (second parameter of `\njq\Executor::run`) defines the number of parallel processes to spawn. This should not exceed the number of available cores in the most cases.

Logger
------

[](#logger)

To view the state of the executor you can specify a logger, which then can echo the current progress. A logger needs to implement the `\njq\Logger` interface and is passed to the constructor of the executor. If no logger is specified a blind dummy logger will be used. To use the shell logger, echoing the state to STDERR, use:

```
