diff --git a/.phan/config.php b/.phan/config.php
index a6bae4f..a4e9bf0 100644
--- a/.phan/config.php
+++ b/.phan/config.php
@@ -383,7 +383,7 @@
// Thus, both first-party and third-party code being used by
// your application should be included in this list.
'directory_list' => [
- 'src/Spork',
+ 'src',
'vendor/symfony/event-dispatcher',
'vendor/symfony/event-dispatcher-contracts',
'vendor/symfony/var-dumper',
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f061f9..b6cf566 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [3.0.0] - 2020-02-02
+
+### Changed
+
+- 4cc83f1: Replace child process shutdown function and improve typings.
+- d6ecf04: Rebrand library to `phpfork`.
+
## [2.0.2] - 2020-02-02
### Changed
@@ -65,9 +72,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added progress callbacks to Deferred.
- Added serializable objects for exit and error messages.
-[Unreleased]: https://github.com/TheLevti/spork/compare/2.0.2...HEAD
-[2.0.2]: https://github.com/TheLevti/spork/releases/2.0.2
-[2.0.1]: https://github.com/TheLevti/spork/releases/2.0.1
-[2.0.0]: https://github.com/TheLevti/spork/releases/2.0.0
-[1.0.0]: https://github.com/TheLevti/spork/releases/1.0.0
-[0.3.0]: https://github.com/TheLevti/spork/releases/0.3.0
+[Unreleased]: https://github.com/TheLevti/phpfork/compare/3.0.0...HEAD
+[3.0.0]: https://github.com/TheLevti/phpfork/releases/3.0.0
+[2.0.2]: https://github.com/TheLevti/phpfork/releases/2.0.2
+[2.0.1]: https://github.com/TheLevti/phpfork/releases/2.0.1
+[2.0.0]: https://github.com/TheLevti/phpfork/releases/2.0.0
+[1.0.0]: https://github.com/TheLevti/phpfork/releases/1.0.0
+[0.3.0]: https://github.com/TheLevti/phpfork/releases/0.3.0
diff --git a/README.md b/README.md
index 99cd47a..2fe88a0 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,13 @@
**[Installation](#installation)** |
**[Usage](#usage)**
-# thelevti/spork
+# thelevti/phpfork
-[![Build Status](https://travis-ci.com/TheLevti/spork.svg?branch=master)](https://travis-ci.com/TheLevti/spork)
+[![Build Status](https://travis-ci.com/TheLevti/phpfork.svg?branch=master)](https://travis-ci.com/TheLevti/phpfork)
PHP on a fork.
-`thelevti/spork` follows semantic versioning. Read more on [semver.org][1].
+`thelevti/phpfork` follows semantic versioning. Read more on [semver.org][1].
----
@@ -29,21 +29,21 @@ To use this library through [composer][5], run the following terminal command
inside your repository's root folder.
```sh
-composer require "thelevti/spork"
+composer require "thelevti/phpfork"
```
## Usage
-This library uses the namespace `Spork`.
+This library uses the namespace `Phpfork`.
```php
fork(function () {
// do something in another process!
return 'Hello from ' . getmypid();
-})->then(function (Spork\Fork $fork) {
+})->then(function (Phpfork\Fork $fork) {
// do something in the parent process when it's done!
echo "{$fork->getPid()} says '{$fork->getResult()}'\n";
});
@@ -60,7 +60,7 @@ multiple batches and spread them across many processes.
$files = new RecursiveDirectoryIterator('/path/to/images');
$files = new RecursiveIteratorIterator($files);
-$manager = new Spork\ProcessManager();
+$manager = new Phpfork\ProcessManager();
$manager->process($files, function(SplFileInfo $file) {
// upload this file
});
@@ -114,15 +114,15 @@ $callback = function ($value) use ($params) {
$parentConnection = Doctrine\DBAL\DriverManager::getConnection($params);
$parentConnection->connect();
-$dispatcher = new Spork\EventDispatcher\EventDispatcher();
-$dispatcher->addListener(Spork\EventDispatcher\Events::PRE_FORK, function () use ($parentConnection) {
+$dispatcher = new Phpfork\EventDispatcher\EventDispatcher();
+$dispatcher->addListener(Phpfork\EventDispatcher\Events::PRE_FORK, function () use ($parentConnection) {
$parentConnection->close();
});
-$manager = new Spork\ProcessManager($dispatcher, null, true);
+$manager = new Phpfork\ProcessManager($dispatcher, null, true);
-/** @var Spork\Fork $fork */
-$fork = $manager->process($dataArray, $callback, new Spork\Batch\Strategy\ChunkStrategy($forks));
+/** @var Phpfork\Fork $fork */
+$fork = $manager->process($dataArray, $callback, new Phpfork\Batch\Strategy\ChunkStrategy($forks));
$manager->wait();
$result = $fork->getResult();
diff --git a/composer.json b/composer.json
index 75803e9..146fe8c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
- "name": "thelevti/spork",
- "description": "PHP on a fork.",
+ "name": "thelevti/phpfork",
+ "description": "PHP process forking library.",
"type": "library",
"keywords": [
"php",
@@ -9,7 +9,7 @@
"async",
"shmop"
],
- "homepage": "https://github.com/TheLevti/spork",
+ "homepage": "https://github.com/TheLevti/phpfork",
"readme": "README.md",
"license": "MIT",
"authors": [
@@ -28,11 +28,11 @@
],
"support": {
"email": "petr@levtonov.com",
- "issues": "https://github.com/TheLevti/spork/issues",
- "wiki": "https://github.com/TheLevti/spork/wiki",
- "source": "https://github.com/TheLevti/spork",
- "docs": "https://github.com/TheLevti/spork/blob/master/README.md",
- "rss": "https://github.com/TheLevti/spork/commits/master.atom"
+ "issues": "https://github.com/TheLevti/phpfork/issues",
+ "wiki": "https://github.com/TheLevti/phpfork/wiki",
+ "source": "https://github.com/TheLevti/phpfork",
+ "docs": "https://github.com/TheLevti/phpfork/blob/master/README.md",
+ "rss": "https://github.com/TheLevti/phpfork/commits/master.atom"
},
"require": {
"php": "^7.2.0",
@@ -51,18 +51,18 @@
},
"autoload": {
"psr-4": {
- "Spork\\": "src/Spork/"
+ "Phpfork\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
- "Spork\\": "tests/Spork/"
+ "Phpfork\\": "tests/"
}
},
"suggest": {
"ext-pnctl": "To allow this library forking processes.",
"ext-posix": "To allow this library getting process information.",
- "ext-shmop": "To allow this library doing interprocess communication."
+ "ext-shmop": "To allow this library doing inter-process communication."
},
"archive": {
"exclude": [
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 659bca3..6ad7559 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,6 +1,6 @@
-
+
./tests
- ./src/Spork
+ ./src
diff --git a/src/Spork/Batch/BatchJob.php b/src/Batch/BatchJob.php
similarity index 86%
rename from src/Spork/Batch/BatchJob.php
rename to src/Batch/BatchJob.php
index de2f17a..cc1fda1 100644
--- a/src/Spork/Batch/BatchJob.php
+++ b/src/Batch/BatchJob.php
@@ -1,20 +1,22 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch;
+declare(strict_types=1);
-use Spork\Batch\Strategy\ChunkStrategy;
-use Spork\Batch\Strategy\StrategyInterface;
-use Spork\Exception\UnexpectedTypeException;
-use Spork\ProcessManager;
+namespace Phpfork\Batch;
+
+use Phpfork\Batch\Strategy\ChunkStrategy;
+use Phpfork\Batch\Strategy\StrategyInterface;
+use Phpfork\Exception\UnexpectedTypeException;
+use Phpfork\ProcessManager;
class BatchJob
{
diff --git a/src/Spork/Batch/BatchRunner.php b/src/Batch/BatchRunner.php
similarity index 84%
rename from src/Spork/Batch/BatchRunner.php
rename to src/Batch/BatchRunner.php
index 50584b3..428b5c2 100644
--- a/src/Spork/Batch/BatchRunner.php
+++ b/src/Batch/BatchRunner.php
@@ -1,18 +1,20 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
-use Spork\SharedMemory;
+namespace Phpfork\Batch;
+
+use Phpfork\Exception\UnexpectedTypeException;
+use Phpfork\SharedMemory;
class BatchRunner
{
diff --git a/src/Spork/Batch/Strategy/AbstractStrategy.php b/src/Batch/Strategy/AbstractStrategy.php
similarity index 63%
rename from src/Spork/Batch/Strategy/AbstractStrategy.php
rename to src/Batch/Strategy/AbstractStrategy.php
index 49d2587..d6fb22e 100644
--- a/src/Spork/Batch/Strategy/AbstractStrategy.php
+++ b/src/Batch/Strategy/AbstractStrategy.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
-use Spork\Batch\BatchRunner;
+namespace Phpfork\Batch\Strategy;
+
+use Phpfork\Batch\BatchRunner;
abstract class AbstractStrategy implements StrategyInterface
{
diff --git a/src/Spork/Batch/Strategy/CallbackStrategy.php b/src/Batch/Strategy/CallbackStrategy.php
similarity index 73%
rename from src/Spork/Batch/Strategy/CallbackStrategy.php
rename to src/Batch/Strategy/CallbackStrategy.php
index ba9ae63..04f50cd 100644
--- a/src/Spork/Batch/Strategy/CallbackStrategy.php
+++ b/src/Batch/Strategy/CallbackStrategy.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
+namespace Phpfork\Batch\Strategy;
+
+use Phpfork\Exception\UnexpectedTypeException;
class CallbackStrategy extends AbstractStrategy
{
diff --git a/src/Spork/Batch/Strategy/ChunkStrategy.php b/src/Batch/Strategy/ChunkStrategy.php
similarity index 81%
rename from src/Spork/Batch/Strategy/ChunkStrategy.php
rename to src/Batch/Strategy/ChunkStrategy.php
index 6f529c0..759709e 100644
--- a/src/Spork/Batch/Strategy/ChunkStrategy.php
+++ b/src/Batch/Strategy/ChunkStrategy.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
+namespace Phpfork\Batch\Strategy;
+
+use Phpfork\Exception\UnexpectedTypeException;
/**
* Creates the batch iterator using array_chunk().
diff --git a/src/Spork/Batch/Strategy/StrategyInterface.php b/src/Batch/Strategy/StrategyInterface.php
similarity index 85%
rename from src/Spork/Batch/Strategy/StrategyInterface.php
rename to src/Batch/Strategy/StrategyInterface.php
index 27d78f5..4fd5e14 100644
--- a/src/Spork/Batch/Strategy/StrategyInterface.php
+++ b/src/Batch/Strategy/StrategyInterface.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
+
+namespace Phpfork\Batch\Strategy;
/**
* @see BatchJob::__invoke()
diff --git a/src/Spork/Batch/Strategy/ThrottleStrategy.php b/src/Batch/Strategy/ThrottleStrategy.php
similarity index 82%
rename from src/Spork/Batch/Strategy/ThrottleStrategy.php
rename to src/Batch/Strategy/ThrottleStrategy.php
index 2e74bf3..f2dc892 100644
--- a/src/Spork/Batch/Strategy/ThrottleStrategy.php
+++ b/src/Batch/Strategy/ThrottleStrategy.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
-use Spork\Util\ThrottleIterator;
+namespace Phpfork\Batch\Strategy;
+
+use Phpfork\Util\ThrottleIterator;
class ThrottleStrategy implements StrategyInterface
{
diff --git a/src/Spork/Deferred/Deferred.php b/src/Deferred/Deferred.php
similarity index 95%
rename from src/Spork/Deferred/Deferred.php
rename to src/Deferred/Deferred.php
index d2cacf2..c2711b9 100644
--- a/src/Spork/Deferred/Deferred.php
+++ b/src/Deferred/Deferred.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
+namespace Phpfork\Deferred;
+
+use Phpfork\Exception\UnexpectedTypeException;
class Deferred implements DeferredInterface
{
diff --git a/src/Spork/Deferred/DeferredAggregate.php b/src/Deferred/DeferredAggregate.php
similarity index 87%
rename from src/Spork/Deferred/DeferredAggregate.php
rename to src/Deferred/DeferredAggregate.php
index 6947d88..70dab6e 100644
--- a/src/Spork/Deferred/DeferredAggregate.php
+++ b/src/Deferred/DeferredAggregate.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
+namespace Phpfork\Deferred;
+
+use Phpfork\Exception\UnexpectedTypeException;
class DeferredAggregate implements PromiseInterface
{
@@ -23,7 +25,7 @@ public function __construct(array $children)
// validate children
foreach ($children as $child) {
if (!$child instanceof PromiseInterface) {
- throw new UnexpectedTypeException($child, 'Spork\Deferred\PromiseInterface');
+ throw new UnexpectedTypeException($child, 'Phpfork\Deferred\PromiseInterface');
}
}
diff --git a/src/Spork/Deferred/DeferredInterface.php b/src/Deferred/DeferredInterface.php
similarity index 88%
rename from src/Spork/Deferred/DeferredInterface.php
rename to src/Deferred/DeferredInterface.php
index 6934925..415b2c3 100644
--- a/src/Spork/Deferred/DeferredInterface.php
+++ b/src/Deferred/DeferredInterface.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
+
+namespace Phpfork\Deferred;
interface DeferredInterface extends PromiseInterface
{
diff --git a/src/Spork/Deferred/PromiseInterface.php b/src/Deferred/PromiseInterface.php
similarity index 93%
rename from src/Spork/Deferred/PromiseInterface.php
rename to src/Deferred/PromiseInterface.php
index e41f520..000d92e 100644
--- a/src/Spork/Deferred/PromiseInterface.php
+++ b/src/Deferred/PromiseInterface.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
+
+namespace Phpfork\Deferred;
interface PromiseInterface
{
diff --git a/src/Spork/EventDispatcher/Events.php b/src/EventDispatcher/Events.php
similarity index 55%
rename from src/Spork/EventDispatcher/Events.php
rename to src/EventDispatcher/Events.php
index f192754..c91e290 100644
--- a/src/Spork/EventDispatcher/Events.php
+++ b/src/EventDispatcher/Events.php
@@ -1,25 +1,27 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\EventDispatcher;
+declare(strict_types=1);
+
+namespace Phpfork\EventDispatcher;
final class Events
{
/**
* Dispatched in the parent process before forking.
*/
- public const PRE_FORK = 'spork.pre_fork';
+ public const PRE_FORK = 'phpfork.pre_fork';
/**
* Notifies in the child process after forking.
*/
- public const POST_FORK = 'spork.post_fork';
+ public const POST_FORK = 'phpfork.post_fork';
}
diff --git a/src/Spork/EventDispatcher/SignalEvent.php b/src/EventDispatcher/SignalEvent.php
similarity index 94%
rename from src/Spork/EventDispatcher/SignalEvent.php
rename to src/EventDispatcher/SignalEvent.php
index 3651297..3952d76 100644
--- a/src/Spork/EventDispatcher/SignalEvent.php
+++ b/src/EventDispatcher/SignalEvent.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event as BaseEvent;
@@ -26,7 +26,7 @@ class SignalEvent extends BaseEvent
*
* @var string PREFIX
*/
- private const PREFIX = 'spork.signal.';
+ private const PREFIX = 'phpfork.signal.';
/**
* The signal being handled.
diff --git a/src/Spork/EventDispatcher/SignalEventDispatcher.php b/src/EventDispatcher/SignalEventDispatcher.php
similarity index 86%
rename from src/Spork/EventDispatcher/SignalEventDispatcher.php
rename to src/EventDispatcher/SignalEventDispatcher.php
index 8c122a3..7352de2 100644
--- a/src/Spork/EventDispatcher/SignalEventDispatcher.php
+++ b/src/EventDispatcher/SignalEventDispatcher.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcher;
diff --git a/src/Spork/EventDispatcher/SignalEventDispatcherInterface.php b/src/EventDispatcher/SignalEventDispatcherInterface.php
similarity index 91%
rename from src/Spork/EventDispatcher/SignalEventDispatcherInterface.php
rename to src/EventDispatcher/SignalEventDispatcherInterface.php
index 644aff7..7d618ae 100644
--- a/src/Spork/EventDispatcher/SignalEventDispatcherInterface.php
+++ b/src/EventDispatcher/SignalEventDispatcherInterface.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -28,7 +28,7 @@ interface SignalEventDispatcherInterface extends EventDispatcherInterface
* @param mixed $signinfo If operating systems supports siginfo_t
* structures, this will be an array of signal
* information dependent on the signal.
- * @return \Spork\EventDispatcher\SignalEvent Holds the signal information.
+ * @return \Phpfork\EventDispatcher\SignalEvent Holds the signal information.
*/
public function dispatchSignal(int $signo, $signinfo): SignalEvent;
diff --git a/src/Spork/EventDispatcher/SignalEventDispatcherTrait.php b/src/EventDispatcher/SignalEventDispatcherTrait.php
similarity index 96%
rename from src/Spork/EventDispatcher/SignalEventDispatcherTrait.php
rename to src/EventDispatcher/SignalEventDispatcherTrait.php
index ae6639e..303efd2 100644
--- a/src/Spork/EventDispatcher/SignalEventDispatcherTrait.php
+++ b/src/EventDispatcher/SignalEventDispatcherTrait.php
@@ -1,7 +1,7 @@
*
@@ -11,9 +11,9 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
-use Spork\Signal\SignalHandlerWrapper;
+use Phpfork\Signal\SignalHandlerWrapper;
use UnexpectedValueException;
/**
@@ -26,7 +26,7 @@ trait SignalEventDispatcherTrait
* Holds signal handler wrappers to preserve a potentially already existing
* signal handler.
*
- * @var array $sigHandlerWrappers
+ * @var array $sigHandlerWrappers
*/
private $sigHandlerWrappers = [];
diff --git a/src/Spork/EventDispatcher/WrappedEventDispatcher.php b/src/EventDispatcher/WrappedEventDispatcher.php
similarity index 96%
rename from src/Spork/EventDispatcher/WrappedEventDispatcher.php
rename to src/EventDispatcher/WrappedEventDispatcher.php
index b563d02..605e894 100644
--- a/src/Spork/EventDispatcher/WrappedEventDispatcher.php
+++ b/src/EventDispatcher/WrappedEventDispatcher.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
diff --git a/src/Spork/Exception/ForkException.php b/src/Exception/ForkException.php
similarity index 88%
rename from src/Spork/Exception/ForkException.php
rename to src/Exception/ForkException.php
index d6c8164..eaeb112 100644
--- a/src/Spork/Exception/ForkException.php
+++ b/src/Exception/ForkException.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Exception;
+declare(strict_types=1);
-use Spork\Util\Error;
+namespace Phpfork\Exception;
+
+use Phpfork\Util\Error;
/**
* Turns an error passed through shared memory into an exception.
diff --git a/src/Spork/Exception/ProcessControlException.php b/src/Exception/ProcessControlException.php
similarity index 58%
rename from src/Spork/Exception/ProcessControlException.php
rename to src/Exception/ProcessControlException.php
index f099f08..4912e25 100644
--- a/src/Spork/Exception/ProcessControlException.php
+++ b/src/Exception/ProcessControlException.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Exception;
+declare(strict_types=1);
+
+namespace Phpfork\Exception;
class ProcessControlException extends \RuntimeException
{
diff --git a/src/Spork/Exception/UnexpectedTypeException.php b/src/Exception/UnexpectedTypeException.php
similarity index 77%
rename from src/Spork/Exception/UnexpectedTypeException.php
rename to src/Exception/UnexpectedTypeException.php
index d78bd7c..a50078e 100644
--- a/src/Spork/Exception/UnexpectedTypeException.php
+++ b/src/Exception/UnexpectedTypeException.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Exception;
+declare(strict_types=1);
+
+namespace Phpfork\Exception;
class UnexpectedTypeException extends \LogicException
{
diff --git a/src/Spork/Factory.php b/src/Factory.php
similarity index 68%
rename from src/Spork/Factory.php
rename to src/Factory.php
index f951022..a93ecce 100644
--- a/src/Spork/Factory.php
+++ b/src/Factory.php
@@ -1,18 +1,20 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork;
+declare(strict_types=1);
-use Spork\Batch\BatchJob;
-use Spork\Batch\Strategy\StrategyInterface;
+namespace Phpfork;
+
+use Phpfork\Batch\BatchJob;
+use Phpfork\Batch\Strategy\StrategyInterface;
class Factory
{
@@ -33,12 +35,12 @@ public function createBatchJob(ProcessManager $manager, $data = null, StrategyIn
/**
* Creates a new shared memory instance.
*
- * @param integer $pid The child process id or null if this is the child
- * @param integer $signal The signal to send after writing to shared memory
+ * @param int|null $pid The child process id or null if this is the child.
+ * @param int|null $signal The signal to send after writing to shared memory.
*
- * @return SharedMemory A new shared memory instance
+ * @return \Phpfork\SharedMemory A new shared memory instance.
*/
- public function createSharedMemory($pid = null, $signal = null)
+ public function createSharedMemory(?int $pid = null, ?int $signal = null): SharedMemory
{
return new SharedMemory($pid, $signal);
}
diff --git a/src/Spork/Fork.php b/src/Fork.php
similarity index 88%
rename from src/Spork/Fork.php
rename to src/Fork.php
index df589a0..5a04341 100644
--- a/src/Spork/Fork.php
+++ b/src/Fork.php
@@ -1,21 +1,23 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork;
+declare(strict_types=1);
-use Spork\Deferred\Deferred;
-use Spork\Deferred\DeferredInterface;
-use Spork\Exception\ForkException;
-use Spork\Exception\ProcessControlException;
-use Spork\Util\ExitMessage;
+namespace Phpfork;
+
+use Phpfork\Deferred\Deferred;
+use Phpfork\Deferred\DeferredInterface;
+use Phpfork\Exception\ForkException;
+use Phpfork\Exception\ProcessControlException;
+use Phpfork\Util\ExitMessage;
class Fork implements DeferredInterface
{
@@ -183,42 +185,42 @@ public function getState()
return $this->defer->getState();
}
- public function progress($progress)
+ public function progress($progress): Fork
{
$this->defer->progress($progress);
return $this;
}
- public function always($always)
+ public function always($always): Fork
{
$this->defer->always($always);
return $this;
}
- public function done($done)
+ public function done($done): Fork
{
$this->defer->done($done);
return $this;
}
- public function fail($fail)
+ public function fail($fail): Fork
{
$this->defer->fail($fail);
return $this;
}
- public function then($done, $fail = null)
+ public function then($done, $fail = null): Fork
{
$this->defer->then($done, $fail);
return $this;
}
- public function notify()
+ public function notify(): Fork
{
$args = func_get_args();
array_unshift($args, $this);
@@ -228,7 +230,7 @@ public function notify()
return $this;
}
- public function resolve()
+ public function resolve(): Fork
{
$args = func_get_args();
array_unshift($args, $this);
@@ -238,7 +240,7 @@ public function resolve()
return $this;
}
- public function reject()
+ public function reject(): Fork
{
$args = func_get_args();
array_unshift($args, $this);
diff --git a/src/Spork/ProcessManager.php b/src/ProcessManager.php
similarity index 71%
rename from src/Spork/ProcessManager.php
rename to src/ProcessManager.php
index 176dde6..59e7645 100644
--- a/src/Spork/ProcessManager.php
+++ b/src/ProcessManager.php
@@ -1,7 +1,7 @@
*
@@ -11,17 +11,17 @@
declare(strict_types=1);
-namespace Spork;
+namespace Phpfork;
+use Exception;
use InvalidArgumentException;
-use Spork\Batch\Strategy\StrategyInterface;
-use Spork\EventDispatcher\Events;
-use Spork\EventDispatcher\SignalEventDispatcher;
-use Spork\EventDispatcher\SignalEventDispatcherInterface;
-use Spork\Exception\ProcessControlException;
-use Spork\Exception\UnexpectedTypeException;
-use Spork\Util\Error;
-use Spork\Util\ExitMessage;
+use Phpfork\Batch\Strategy\StrategyInterface;
+use Phpfork\EventDispatcher\Events;
+use Phpfork\EventDispatcher\SignalEventDispatcher;
+use Phpfork\EventDispatcher\SignalEventDispatcherInterface;
+use Phpfork\Exception\ProcessControlException;
+use Phpfork\Util\Error;
+use Phpfork\Util\ExitMessage;
use Symfony\Contracts\EventDispatcher\Event;
class ProcessManager
@@ -33,7 +33,7 @@ class ProcessManager
private $zombieOkay;
private $signal;
- /** @var Fork[] */
+ /** @var array $forks */
private $forks;
public function __construct(
@@ -87,63 +87,40 @@ public function process($data, $callable, StrategyInterface $strategy = null)
/**
* Forks something into another process and returns a deferred object.
+ *
+ * @param callable $callable Code to execute in a fork.
+ * @return \Phpfork\Fork Newly created fork.
*/
- public function fork($callable)
+ public function fork(callable $callable): Fork
{
- if (!is_callable($callable)) {
- throw new UnexpectedTypeException($callable, 'callable');
- }
-
// allow the system to cleanup before forking
call_user_func([$this->dispatcher, 'dispatch'], new Event(), Events::PRE_FORK);
- if (-1 === $pid = pcntl_fork()) {
- throw new ProcessControlException('Unable to fork a new process');
+ if (-1 === ($pid = pcntl_fork())) {
+ throw new ProcessControlException('Unable to fork a new process.');
}
if (0 === $pid) {
// reset the list of child processes
$this->forks = [];
- // setup the shared memory
- $shm = $this->factory->createSharedMemory(null, $this->signal);
- $message = new ExitMessage();
-
- // phone home on shutdown
- $currPid = posix_getpid();
- register_shutdown_function(function () use ($currPid, $shm, $message): void {
- // Do not execute this function in child processes.
- if ($currPid !== posix_getpid()) {
- return;
- }
-
- try {
- $shm->send($message, false);
- } catch (\Exception $e) {
- // probably an error serializing the result
- $message->setResult(null);
- $message->setError(Error::fromException($e));
-
- $shm->send($message, false);
-
- exit(2);
- }
- });
-
// dispatch an event so the system knows it's in a new process
call_user_func([$this->dispatcher, 'dispatch'], new Event(), Events::POST_FORK);
+ // setup the shared memory and exit message.
+ $shm = $this->factory->createSharedMemory(null, $this->signal);
+ $message = new ExitMessage();
+
if (!$this->debug) {
ob_start();
}
try {
$result = call_user_func($callable, $shm);
-
$message->setResult($result);
$status = is_integer($result) ? $result : 0;
- } catch (\Exception $e) {
- $message->setError(Error::fromException($e));
+ } catch (Exception $exception) {
+ $message->setError(Error::fromException($exception));
$status = 1;
}
@@ -151,13 +128,26 @@ public function fork($callable)
$message->setOutput(ob_get_clean());
}
+ try {
+ $shm->send($message, false);
+ } catch (Exception $exception) {
+ // probably an error serializing the result
+ $message->setResult(null);
+ $message->setError(Error::fromException($exception));
+
+ $shm->send($message, false);
+
+ $status = 2;
+ }
+
exit($status);
}
- // connect to shared memory
- $shm = $this->factory->createSharedMemory($pid);
-
- return $this->forks[$pid] = $this->factory->createFork($pid, $shm, $this->debug);
+ return $this->forks[$pid] = $this->factory->createFork(
+ $pid,
+ $this->factory->createSharedMemory($pid),
+ $this->debug
+ );
}
public function monitor($signal = SIGUSR1)
diff --git a/src/Spork/SharedMemory.php b/src/SharedMemory.php
similarity index 97%
rename from src/Spork/SharedMemory.php
rename to src/SharedMemory.php
index 6414def..e0880ec 100644
--- a/src/Spork/SharedMemory.php
+++ b/src/SharedMemory.php
@@ -1,7 +1,7 @@
*
@@ -11,9 +11,9 @@
declare(strict_types=1);
-namespace Spork;
+namespace Phpfork;
-use Spork\Exception\ProcessControlException;
+use Phpfork\Exception\ProcessControlException;
/**
* Sends messages between processes.
diff --git a/src/Spork/Signal/SignalHandlerWrapper.php b/src/Signal/SignalHandlerWrapper.php
similarity index 97%
rename from src/Spork/Signal/SignalHandlerWrapper.php
rename to src/Signal/SignalHandlerWrapper.php
index 50448c5..64b9306 100644
--- a/src/Spork/Signal/SignalHandlerWrapper.php
+++ b/src/Signal/SignalHandlerWrapper.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\Signal;
+namespace Phpfork\Signal;
/**
* Wraps an existing signal handler with a new signal handler.
diff --git a/src/Spork/Util/Error.php b/src/Util/Error.php
similarity index 96%
rename from src/Spork/Util/Error.php
rename to src/Util/Error.php
index cab5df8..1162c41 100644
--- a/src/Spork/Util/Error.php
+++ b/src/Util/Error.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\Util;
+namespace Phpfork\Util;
use Serializable;
diff --git a/src/Spork/Util/ExitMessage.php b/src/Util/ExitMessage.php
similarity index 88%
rename from src/Spork/Util/ExitMessage.php
rename to src/Util/ExitMessage.php
index b212f97..19e3191 100644
--- a/src/Spork/Util/ExitMessage.php
+++ b/src/Util/ExitMessage.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Util;
+declare(strict_types=1);
+
+namespace Phpfork\Util;
class ExitMessage implements \Serializable
{
diff --git a/src/Spork/Util/ThrottleIterator.php b/src/Util/ThrottleIterator.php
similarity index 92%
rename from src/Spork/Util/ThrottleIterator.php
rename to src/Util/ThrottleIterator.php
index 086e240..c6cf8cc 100644
--- a/src/Spork/Util/ThrottleIterator.php
+++ b/src/Util/ThrottleIterator.php
@@ -1,17 +1,19 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Util;
+declare(strict_types=1);
-use Spork\Exception\UnexpectedTypeException;
+namespace Phpfork\Util;
+
+use Phpfork\Exception\UnexpectedTypeException;
/**
* Throttles iteration based on a system load threshold.
diff --git a/tests/Spork/Batch/Strategy/ChunkStrategyTest.php b/tests/Batch/Strategy/ChunkStrategyTest.php
similarity index 85%
rename from tests/Spork/Batch/Strategy/ChunkStrategyTest.php
rename to tests/Batch/Strategy/ChunkStrategyTest.php
index 7890ffc..c898cd3 100644
--- a/tests/Spork/Batch/Strategy/ChunkStrategyTest.php
+++ b/tests/Batch/Strategy/ChunkStrategyTest.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Batch\Strategy;
+declare(strict_types=1);
+
+namespace Phpfork\Batch\Strategy;
use PHPUnit\Framework\TestCase;
diff --git a/tests/Spork/Deferred/DeferredAggregateTest.php b/tests/Deferred/DeferredAggregateTest.php
similarity index 93%
rename from tests/Spork/Deferred/DeferredAggregateTest.php
rename to tests/Deferred/DeferredAggregateTest.php
index 0eaa8d6..444a24e 100644
--- a/tests/Spork/Deferred/DeferredAggregateTest.php
+++ b/tests/Deferred/DeferredAggregateTest.php
@@ -1,18 +1,20 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
+namespace Phpfork\Deferred;
+
+use Phpfork\Exception\UnexpectedTypeException;
use PHPUnit\Framework\TestCase;
-use Spork\Exception\UnexpectedTypeException;
class DeferredAggregateTest extends TestCase
{
diff --git a/tests/Spork/Deferred/DeferredTest.php b/tests/Deferred/DeferredTest.php
similarity index 95%
rename from tests/Spork/Deferred/DeferredTest.php
rename to tests/Deferred/DeferredTest.php
index fc256f7..9f99f5b 100644
--- a/tests/Spork/Deferred/DeferredTest.php
+++ b/tests/Deferred/DeferredTest.php
@@ -1,19 +1,21 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Deferred;
+declare(strict_types=1);
+
+namespace Phpfork\Deferred;
use LogicException;
+use Phpfork\Exception\UnexpectedTypeException;
use PHPUnit\Framework\TestCase;
-use Spork\Exception\UnexpectedTypeException;
class DeferredTest extends TestCase
{
diff --git a/tests/Spork/EventDispatcher/SignalEventDispatcherTest.php b/tests/EventDispatcher/SignalEventDispatcherTest.php
similarity index 88%
rename from tests/Spork/EventDispatcher/SignalEventDispatcherTest.php
rename to tests/EventDispatcher/SignalEventDispatcherTest.php
index 6f5d73e..a5527ee 100644
--- a/tests/Spork/EventDispatcher/SignalEventDispatcherTest.php
+++ b/tests/EventDispatcher/SignalEventDispatcherTest.php
@@ -1,7 +1,7 @@
*
@@ -11,10 +11,10 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
+use Phpfork\ProcessManager;
use PHPUnit\Framework\TestCase;
-use Spork\ProcessManager;
class SignalEventDispatcherTest extends TestCase
{
@@ -23,7 +23,7 @@ class SignalEventDispatcherTest extends TestCase
/**
* Process manager instance.
*
- * @var \Spork\ProcessManager $processManager
+ * @var \Phpfork\ProcessManager $processManager
*/
private $processManager;
diff --git a/tests/Spork/EventDispatcher/SignalEventDispatcherTestTrait.php b/tests/EventDispatcher/SignalEventDispatcherTestTrait.php
similarity index 98%
rename from tests/Spork/EventDispatcher/SignalEventDispatcherTestTrait.php
rename to tests/EventDispatcher/SignalEventDispatcherTestTrait.php
index d0c4d80..dce2416 100644
--- a/tests/Spork/EventDispatcher/SignalEventDispatcherTestTrait.php
+++ b/tests/EventDispatcher/SignalEventDispatcherTestTrait.php
@@ -1,7 +1,7 @@
*
@@ -11,10 +11,10 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
+use Phpfork\SharedMemory;
use ReflectionObject;
-use Spork\SharedMemory;
use Symfony\Component\EventDispatcher\EventDispatcher;
use UnexpectedValueException;
diff --git a/tests/Spork/EventDispatcher/SignalEventSubscriber.php b/tests/EventDispatcher/SignalEventSubscriber.php
similarity index 86%
rename from tests/Spork/EventDispatcher/SignalEventSubscriber.php
rename to tests/EventDispatcher/SignalEventSubscriber.php
index c01299f..19a6abf 100644
--- a/tests/Spork/EventDispatcher/SignalEventSubscriber.php
+++ b/tests/EventDispatcher/SignalEventSubscriber.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
diff --git a/tests/Spork/EventDispatcher/WrappedEventDispatcherTest.php b/tests/EventDispatcher/WrappedEventDispatcherTest.php
similarity index 93%
rename from tests/Spork/EventDispatcher/WrappedEventDispatcherTest.php
rename to tests/EventDispatcher/WrappedEventDispatcherTest.php
index 61223a3..38e235d 100644
--- a/tests/Spork/EventDispatcher/WrappedEventDispatcherTest.php
+++ b/tests/EventDispatcher/WrappedEventDispatcherTest.php
@@ -1,7 +1,7 @@
*
@@ -11,10 +11,10 @@
declare(strict_types=1);
-namespace Spork\EventDispatcher;
+namespace Phpfork\EventDispatcher;
+use Phpfork\ProcessManager;
use PHPUnit\Framework\TestCase;
-use Spork\ProcessManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
class WrappedEventDispatcherTest extends TestCase
@@ -24,7 +24,7 @@ class WrappedEventDispatcherTest extends TestCase
/**
* Process manager instance.
*
- * @var \Spork\ProcessManager $processManager
+ * @var \Phpfork\ProcessManager $processManager
*/
private $processManager;
diff --git a/tests/Spork/ProcessManagerTest.php b/tests/ProcessManagerTest.php
similarity index 98%
rename from tests/Spork/ProcessManagerTest.php
rename to tests/ProcessManagerTest.php
index 434fd47..32fe320 100644
--- a/tests/Spork/ProcessManagerTest.php
+++ b/tests/ProcessManagerTest.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork;
+namespace Phpfork;
use Exception;
use PHPUnit\Framework\TestCase;
diff --git a/tests/Spork/Signal/SignalHandlerWrapperTest.php b/tests/Signal/SignalHandlerWrapperTest.php
similarity index 94%
rename from tests/Spork/Signal/SignalHandlerWrapperTest.php
rename to tests/Signal/SignalHandlerWrapperTest.php
index 3e8b060..1ec5cee 100644
--- a/tests/Spork/Signal/SignalHandlerWrapperTest.php
+++ b/tests/Signal/SignalHandlerWrapperTest.php
@@ -1,7 +1,7 @@
*
@@ -11,7 +11,7 @@
declare(strict_types=1);
-namespace Spork\Signal;
+namespace Phpfork\Signal;
use PHPUnit\Framework\TestCase;
diff --git a/tests/Spork/Util/ThrottleIteratorStub.php b/tests/Util/ThrottleIteratorStub.php
similarity index 74%
rename from tests/Spork/Util/ThrottleIteratorStub.php
rename to tests/Util/ThrottleIteratorStub.php
index ab6deba..6230f36 100644
--- a/tests/Spork/Util/ThrottleIteratorStub.php
+++ b/tests/Util/ThrottleIteratorStub.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Util;
+declare(strict_types=1);
+
+namespace Phpfork\Util;
class ThrottleIteratorStub extends ThrottleIterator
{
diff --git a/tests/Spork/Util/ThrottleIteratorTest.php b/tests/Util/ThrottleIteratorTest.php
similarity index 82%
rename from tests/Spork/Util/ThrottleIteratorTest.php
rename to tests/Util/ThrottleIteratorTest.php
index 0516698..f440e15 100644
--- a/tests/Spork/Util/ThrottleIteratorTest.php
+++ b/tests/Util/ThrottleIteratorTest.php
@@ -1,15 +1,17 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Spork\Util;
+declare(strict_types=1);
+
+namespace Phpfork\Util;
use PHPUnit\Framework\TestCase;