Skip to content

Commit

Permalink
Defer checks for ext/pcntl until instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 28, 2022
1 parent 534f807 commit e45481c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Networking changelog

## ?.?.? / ????-??-??

## 10.3.1 / 2022-08-28

* Fixed package reflection for `peer.server` by deferring the check for
`ext/pcntl` until server implementations based on its functionality
are instantiated, not just loaded
(@thekid)

## 10.3.0 / 2022-08-26

* Merged PR #24: Simplify peer.net API, implementing features sugggested
Expand Down
14 changes: 13 additions & 1 deletion src/main/php/peer/server/ForkingServer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
*/
class ForkingServer extends Server {
use Pcntl;


/**
* Constructor
*
* @param string $addr
* @param int $port
* @throws lang.IllegalAccessException
*/
public function __construct($addr, $port) {
self::extension();
parent::__construct($addr, $port);
}

/**
* Service
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/php/peer/server/Pcntl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

trait Pcntl {

static function __static() {
/** Verify PCNTL extension is loaded and useable */
private static function extension() {
if (!extension_loaded('pcntl')) {
throw new IllegalAccessException('PCNTL extension not available');
throw new IllegalAccessException('PCNTL extension not loaded');
}

// https://stackoverflow.com/questions/16262854/pcntl-not-working-on-ubuntu-for-security-reasons
Expand Down
10 changes: 6 additions & 4 deletions src/main/php/peer/server/PreforkingServer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class PreforkingServer extends Server implements Traceable {
/**
* Constructor
*
* @param string addr
* @param int port
* @param int count default 10 number of children to fork
* @param int maxrequests default 1000 maxmimum # of requests per child
* @param string $addr
* @param int $port
* @param int $count default 10 number of children to fork
* @param int $maxrequests default 1000 maxmimum # of requests per child
* @throws lang.IllegalAccessException
*/
public function __construct($addr, $port, $count= 10, $maxrequests= 1000) {
self::extension();
parent::__construct($addr, $port);
$this->count= (int)$count;
$this->maxrequests= (int)$maxrequests;
Expand Down

0 comments on commit e45481c

Please sign in to comment.