Skip to content

Commit

Permalink
Merge pull request #276 from WyriHaximus-labs/3.x-raise-minimum-php-v…
Browse files Browse the repository at this point in the history
…ersion-to-7.1PLUS

Update to require PHP 7.1+
  • Loading branch information
WyriHaximus authored May 23, 2024
2 parents 229fb29 + cde4017 commit f2fb5a2
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 395 deletions.
26 changes: 2 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand All @@ -32,7 +27,7 @@ jobs:
coverage: xdebug
ini-file: development
ini-values: disable_functions='' # do not disable PCNTL functions on PHP < 8.1
extensions: sockets, pcntl ${{ matrix.php >= 5.6 && ', event' || '' }} ${{ matrix.php >= 5.4 && ', ev' || '' }}
extensions: sockets, pcntl, event, ev
env:
fail-fast: true # fail step if any extension can not be installed
- run: composer install
Expand All @@ -56,7 +51,6 @@ jobs:
- 7.3
- 7.2
- 7.1
- 7.0
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand All @@ -65,7 +59,7 @@ jobs:
coverage: xdebug
ini-file: development
extensions: sockets, pcntl
- name: Install ext-uv on PHP 7+
- name: Install ext-uv
run: |
sudo apt-get update -q && sudo apt-get install libuv1-dev
echo "yes" | sudo pecl install ${{ matrix.php >= 8.0 && 'uv-0.3.0' || 'uv-0.2.4' }}
Expand Down Expand Up @@ -104,19 +98,3 @@ jobs:
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}

PHPUnit-hhvm:
name: PHPUnit (HHVM)
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- uses: actions/checkout@v4
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
- name: Run hhvm composer.phar install
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm composer.phar install
- name: Run hhvm vendor/bin/phpunit
uses: docker://hhvm/hhvm:3.30-lts-latest
with:
args: hhvm vendor/bin/phpunit
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ A `stream_select()` based event loop.
This uses the [`stream_select()`](https://www.php.net/manual/en/function.stream-select.php)
function and is the only implementation that works out of the box with PHP.

This event loop works out of the box on PHP 5.3 through PHP 8+ and HHVM.
This event loop works out of the box on any PHP version.
This means that no installation is required and this library works on all
platforms and supported PHP versions.
Accordingly, the [`Loop` class](#loop) will use this event loop by default if
Expand Down Expand Up @@ -373,7 +373,7 @@ This uses the [`event` PECL extension](https://pecl.php.net/package/event),
that provides an interface to `libevent` library.
`libevent` itself supports a number of system-specific backends (epoll, kqueue).

This loop is known to work with PHP 5.4 through PHP 8+.
This loop is known to work with PHP 7.1 through PHP 8+.

#### ExtEvLoop

Expand All @@ -384,7 +384,7 @@ that provides an interface to `libev` library.
`libev` itself supports a number of system-specific backends (epoll, kqueue).


This loop is known to work with PHP 5.4 through PHP 8+.
This loop is known to work with PHP 7.1 through PHP 8+.

#### ExtUvLoop

Expand All @@ -394,7 +394,7 @@ This loop uses the [`uv` PECL extension](https://pecl.php.net/package/uv),
that provides an interface to `libuv` library.
`libuv` itself supports a number of system-specific backends (epoll, kqueue).

This loop is known to work with PHP 7+.
This loop is known to work with PHP 7.1 through PHP 8+.

### LoopInterface

Expand Down Expand Up @@ -830,8 +830,7 @@ composer require react/event-loop:^3@dev
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
HHVM.
extensions and supports running on PHP 7.1 through current PHP 8+.
It's *highly recommended to use the latest supported PHP version* for this project.

Installing any of the event loop extensions is suggested, but entirely optional.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
"phpunit/phpunit": "^9.6 || ^7.5"
},
"suggest": {
"ext-pcntl": "For signal handling support when using the StreamSelectLoop"
Expand Down
2 changes: 1 addition & 1 deletion examples/12-generate-yes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require __DIR__ . '/../vendor/autoload.php';

// data can be given as first argument or defaults to "y"
$data = (isset($argv[1]) ? $argv[1] : 'y') . "\n";
$data = ($argv[1] ?? 'y') . "\n";

// repeat data X times in order to fill around 200 KB
$data = str_repeat($data, round(200000 / strlen($data)));
Expand Down
2 changes: 1 addition & 1 deletion examples/91-benchmark-ticks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__ . '/../vendor/autoload.php';

$n = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
$n = (int) ($argv[1] ?? 1000 * 100);

for ($i = 0; $i < $n; ++$i) {
Loop::futureTick(function () { });
Expand Down
2 changes: 1 addition & 1 deletion examples/92-benchmark-timers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__ . '/../vendor/autoload.php';

$n = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
$n = (int) ($argv[1] ?? 1000 * 100);

for ($i = 0; $i < $n; ++$i) {
Loop::addTimer(0, function () { });
Expand Down
2 changes: 1 addition & 1 deletion examples/93-benchmark-ticks-delay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__ . '/../vendor/autoload.php';

$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
$ticks = (int) ($argv[1] ?? 1000 * 100);
$tick = function () use (&$tick, &$ticks) {
if ($ticks > 0) {
--$ticks;
Expand Down
2 changes: 1 addition & 1 deletion examples/94-benchmark-timers-delay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__ . '/../vendor/autoload.php';

$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
$ticks = (int) ($argv[1] ?? 1000 * 100);
$tick = function () use (&$tick, &$ticks) {
if ($ticks > 0) {
--$ticks;
Expand Down
4 changes: 2 additions & 2 deletions examples/95-benchmark-memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
require __DIR__ . '/../vendor/autoload.php';

$args = getopt('t:l:r:');
$t = isset($args['t']) ? (int)$args['t'] : 0;
$t = (int) ($args['t'] ?? 0);
$loop = isset($args['l']) && class_exists('React\EventLoop\\' . $args['l'] . 'Loop') ? 'React\EventLoop\\' . $args['l'] . 'Loop' : Loop::get();

if (!($loop instanceof LoopInterface)) {
Loop::set(new $loop());
}

$r = isset($args['r']) ? (int)$args['r'] : 2;
$r = (int) ($args['r'] ?? 2);

$runs = 0;

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
Expand Down
16 changes: 7 additions & 9 deletions src/ExtEvLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* that provides an interface to `libev` library.
* `libev` itself supports a number of system-specific backends (epoll, kqueue).
*
* This loop is known to work with PHP 5.4 through PHP 8+.
* This loop is known to work with PHP 7.1 through PHP 8+.
*
* @see http://php.net/manual/en/book.ev.php
* @see https://bitbucket.org/osmanov/pecl-ev/overview
Expand All @@ -41,12 +41,12 @@ class ExtEvLoop implements LoopInterface
/**
* @var EvIo[]
*/
private $readStreams = array();
private $readStreams = [];

/**
* @var EvIo[]
*/
private $writeStreams = array();
private $writeStreams = [];

/**
* @var bool
Expand All @@ -61,7 +61,7 @@ class ExtEvLoop implements LoopInterface
/**
* @var \EvSignal[]
*/
private $signalEvents = array();
private $signalEvents = [];

public function __construct()
{
Expand Down Expand Up @@ -138,13 +138,11 @@ public function addTimer($interval, $callback)
{
$timer = new Timer($interval, $callback, false);

$that = $this;
$timers = $this->timers;
$callback = function () use ($timer, $timers, $that) {
$callback = function () use ($timer) {
\call_user_func($timer->getCallback(), $timer);

if ($timers->contains($timer)) {
$that->cancelTimer($timer);
if ($this->timers->contains($timer)) {
$this->cancelTimer($timer);
}
};

Expand Down
47 changes: 20 additions & 27 deletions src/ExtEventLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* that provides an interface to `libevent` library.
* `libevent` itself supports a number of system-specific backends (epoll, kqueue).
*
* This loop is known to work with PHP 5.4 through PHP 8+.
* This loop is known to work with PHP 7.1 through PHP 8+.
*
* @link https://pecl.php.net/package/event
*/
Expand All @@ -27,15 +27,15 @@ final class ExtEventLoop implements LoopInterface
private $timerCallback;
private $timerEvents;
private $streamCallback;
private $readEvents = array();
private $writeEvents = array();
private $readListeners = array();
private $writeListeners = array();
private $readRefs = array();
private $writeRefs = array();
private $readEvents = [];
private $writeEvents = [];
private $readListeners = [];
private $writeListeners = [];
private $readRefs = [];
private $writeRefs = [];
private $running;
private $signals;
private $signalEvents = array();
private $signalEvents = [];

public function __construct()
{
Expand Down Expand Up @@ -67,8 +67,8 @@ public function __destruct()
$this->timerEvents->detach($timer);
}

$this->readEvents = array();
$this->writeEvents = array();
$this->readEvents = [];
$this->writeEvents = [];
}

public function addReadStream($stream, $listener)
Expand All @@ -85,9 +85,7 @@ public function addReadStream($stream, $listener)

// ext-event does not increase refcount on stream resources for PHP 7+
// manually keep track of stream resource to prevent premature garbage collection
if (\PHP_VERSION_ID >= 70000) {
$this->readRefs[$key] = $stream;
}
$this->readRefs[$key] = $stream;
}

public function addWriteStream($stream, $listener)
Expand All @@ -104,9 +102,7 @@ public function addWriteStream($stream, $listener)

// ext-event does not increase refcount on stream resources for PHP 7+
// manually keep track of stream resource to prevent premature garbage collection
if (\PHP_VERSION_ID >= 70000) {
$this->writeRefs[$key] = $stream;
}
$this->writeRefs[$key] = $stream;
}

public function removeReadStream($stream)
Expand Down Expand Up @@ -173,7 +169,7 @@ public function addSignal($signal, $listener)
$this->signals->add($signal, $listener);

if (!isset($this->signalEvents[$signal])) {
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, array($this->signals, 'call'));
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, [$this->signals, 'call']);
$this->signalEvents[$signal]->add();
}
}
Expand Down Expand Up @@ -239,11 +235,10 @@ private function scheduleTimer(TimerInterface $timer)
*/
private function createTimerCallback()
{
$timers = $this->timerEvents;
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
$this->timerCallback = function ($_, $__, $timer) {
\call_user_func($timer->getCallback(), $timer);

if (!$timer->isPeriodic() && $timers->contains($timer)) {
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
$this->cancelTimer($timer);
}
};
Expand All @@ -258,17 +253,15 @@ private function createTimerCallback()
*/
private function createStreamCallback()
{
$read =& $this->readListeners;
$write =& $this->writeListeners;
$this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
$this->streamCallback = function ($stream, $flags) {
$key = (int) $stream;

if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
\call_user_func($read[$key], $stream);
if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
\call_user_func($this->readListeners[$key], $stream);
}

if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
\call_user_func($write[$key], $stream);
if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
\call_user_func($this->writeListeners[$key], $stream);
}
};
}
Expand Down
Loading

0 comments on commit f2fb5a2

Please sign in to comment.