PHPackages                             muhammads92/simple-multi-threader - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. muhammads92/simple-multi-threader

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

muhammads92/simple-multi-threader
=================================

1.0.3(5y ago)137MITPHP

Since May 3Pushed 5y agoCompare

[ Source](https://github.com/muhammad1992/simple-multi-threader)[ Packagist](https://packagist.org/packages/muhammads92/simple-multi-threader)[ RSS](/packages/muhammads92-simple-multi-threader/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (7)Used By (0)

Simple Multi Threader
=====================

[](#simple-multi-threader)

A simple PHP Multithreader extension which is ready for use without any setups or configurations.

- No need to integrate any Queues or similar implementations
- Write the code you want to process in the background in a closure(anonymous function) along with arguments(if any) and provide it to the extension. That's all.
- Works with Core PHP(Normal PHP), Laravel and Yii2 out of the box.
- Can work with any PHP Framework/Platform by just adding the required bootstrap code(See [here](https://github.com/muhammads92/simple-multi-threader#making-it-compatible-with-the-platform-you-use)).
- Compatible with PHP installations in Windows and \*nix(Unix like)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require muhammads92/simple-multi-threader

```

or add

```
"muhammads92/simple-multi-threader": "*"
```

to the `require` section of your composer.json.

How to use
----------

[](#how-to-use)

If you want to run some code in the background, just provide it in a closure(anonymous function) to an object of the class `Threader` as below:

```
$threader = new cs\simplemultithreader\Threader(['arguments' => ['myObject' => new \stdClass, 'myArray' => ['a', 'b', 'c']]]);
$jobId = $threader->thread(function($arguments){
	//your code here..
 	//you can access any of the above given $arguments here like $arguments['myObject'] or $arguments['myArray']
});

```

That's all, the Threader will create the required job files in the specified `$jobsDir` and will start a PHP process in the background executing your code. The main thread(code above and after `$threader->thread...`) will run without waiting for the sub-thread(code in the closure) to finish. You will also get the started job's id(an md5 string) as the return value of the method `thread` which you can use for [debugging](https://github.com/muhammads92/simple-multi-threader#debugging).

Any data returned from the closure function will be logged to a file with name `smt_.log` in the default directory specified for logs: `smt-logs`.

Configurable Options
--------------------

[](#configurable-options)

`$arguments` - Arguments for the closure - type: mixed, default = null

`$jobsDir` - Directory(auto-created if not existing) where temporary job files will be stored - type: string, default = `"smt-jobs"`

`$logsDir` - Directory(auto-created if not existing) where log files will be stored - type: string, default = `"smt-logs"`

`$nohup` - Whether to ignore the HUP (hangup) signal in Unix based systems - type: boolean, default = `true`

`$helperClass` - Fully qualified class name of the Helper to be used. - type: string, default = `"cs\\simplemultithreader\\CommandHelper"`

Any option above can be used to configure the Threader in the below way:

```
$threader = new cs\simplemultithreader\Threader(['jobsDir' => 'MyJobsDir', 'helperClass' => '\namespace\of\MyHelperClass']);

```

or like:

```
$threader = new cs\simplemultithreader\Threader;
$threader->arguments = ['myObject' => new \stdClass, 'myArray' => ['a', 'b', 'c']];
$threader->jobsDir = 'MyJobsDir';
...

```

Making it compatible with the platform you use
----------------------------------------------

[](#making-it-compatible-with-the-platform-you-use)

Even if your application is not built either on Core PHP, Laravel or Yii2 which are already supported, you can make it compatible with this extension by the below steps:

There are two ways to accomplish this:

1. Easiest way - Insert the bootstrap code of your Platform before your code in the closure.

    ```
    $jobId = $threader->thread(function($arguments){
       //bootstrap code here..
       //your actual code here..
    });

    ```
2. Recommended way - Extend `$helperClass` with your own Helper class and include the corresponding bootstrap function in it as below:

    Suppose the platform you use is WordPress. Create a function in the extended Class as below:

    ```
    public function executeWordpressBootStrap(){
       //code required to bootstrap Wordpress..
    }

    ```

    and override the `getPlatform` method to just return the string 'wordpress'(as WordPress is the only platform you use in that app) as below:

    ```
    public function getPlatform(){
        return 'wordpress';
    }

    ```

    That's all! `executeWordpressBootStrap` will be executed before executing your code allowing Wordpress's native functions and usages in your code inside the Closure.

    By doing this just once, the extension is now ready for executing any code(normal and platform related) anywhere in your Platform. You're also getting the freedom to override any additional logic defined in the `CommandHelper` class.

    **Pull Requests for supporting additional platforms are always welcome!**

Debugging
---------

[](#debugging)

Whenever an exception gets thrown from your code provided in the closure, it will be logged with a filename: `smt__error.log`. You can find the details of the error including the Stack Trace inside it.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 89.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~31 days

Total

7

Last Release

2067d ago

Major Versions

0.21 → 1.0.02020-05-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/52d3f59512151b341366e9690932aed3daf6443aa2fcb37286aad41e25148744?d=identicon)[muhammads92](/maintainers/muhammads92)

---

Top Contributors

[![codespede](https://avatars.githubusercontent.com/u/1932084?v=4)](https://github.com/codespede "codespede (25 commits)")[![muhammad1992](https://avatars.githubusercontent.com/u/5596722?v=4)](https://github.com/muhammad1992 "muhammad1992 (3 commits)")

### Embed Badge

![Health badge](/badges/muhammads92-simple-multi-threader/health.svg)

```
[![Health](https://phpackages.com/badges/muhammads92-simple-multi-threader/health.svg)](https://phpackages.com/packages/muhammads92-simple-multi-threader)
```

###  Alternatives

[heptacom/heptaconnect-portal-base

HEPTAconnect base dataset that every other portal is based on

1024.9k13](/packages/heptacom-heptaconnect-portal-base)[codespede/simple-multi-threader

122.6k](/packages/codespede-simple-multi-threader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
