Skip to content

Commit f2fb5a2

Browse files
authored
Merge pull request #276 from WyriHaximus-labs/3.x-raise-minimum-php-version-to-7.1PLUS
Update to require PHP 7.1+
2 parents 229fb29 + cde4017 commit f2fb5a2

25 files changed

+255
-395
lines changed

.github/workflows/ci.yml

+2-24
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
- 7.3
2020
- 7.2
2121
- 7.1
22-
- 7.0
23-
- 5.6
24-
- 5.5
25-
- 5.4
26-
- 5.3
2722
steps:
2823
- uses: actions/checkout@v4
2924
- uses: shivammathur/setup-php@v2
@@ -32,7 +27,7 @@ jobs:
3227
coverage: xdebug
3328
ini-file: development
3429
ini-values: disable_functions='' # do not disable PCNTL functions on PHP < 8.1
35-
extensions: sockets, pcntl ${{ matrix.php >= 5.6 && ', event' || '' }} ${{ matrix.php >= 5.4 && ', ev' || '' }}
30+
extensions: sockets, pcntl, event, ev
3631
env:
3732
fail-fast: true # fail step if any extension can not be installed
3833
- run: composer install
@@ -56,7 +51,6 @@ jobs:
5651
- 7.3
5752
- 7.2
5853
- 7.1
59-
- 7.0
6054
steps:
6155
- uses: actions/checkout@v4
6256
- uses: shivammathur/setup-php@v2
@@ -65,7 +59,7 @@ jobs:
6559
coverage: xdebug
6660
ini-file: development
6761
extensions: sockets, pcntl
68-
- name: Install ext-uv on PHP 7+
62+
- name: Install ext-uv
6963
run: |
7064
sudo apt-get update -q && sudo apt-get install libuv1-dev
7165
echo "yes" | sudo pecl install ${{ matrix.php >= 8.0 && 'uv-0.3.0' || 'uv-0.2.4' }}
@@ -104,19 +98,3 @@ jobs:
10498
if: ${{ matrix.php >= 7.3 }}
10599
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
106100
if: ${{ matrix.php < 7.3 }}
107-
108-
PHPUnit-hhvm:
109-
name: PHPUnit (HHVM)
110-
runs-on: ubuntu-22.04
111-
continue-on-error: true
112-
steps:
113-
- uses: actions/checkout@v4
114-
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
115-
- name: Run hhvm composer.phar install
116-
uses: docker://hhvm/hhvm:3.30-lts-latest
117-
with:
118-
args: hhvm composer.phar install
119-
- name: Run hhvm vendor/bin/phpunit
120-
uses: docker://hhvm/hhvm:3.30-lts-latest
121-
with:
122-
args: hhvm vendor/bin/phpunit

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ A `stream_select()` based event loop.
330330
This uses the [`stream_select()`](https://www.php.net/manual/en/function.stream-select.php)
331331
function and is the only implementation that works out of the box with PHP.
332332

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

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

378378
#### ExtEvLoop
379379

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

386386

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

389389
#### ExtUvLoop
390390

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

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

399399
### LoopInterface
400400

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

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

837836
Installing any of the event loop extensions is suggested, but entirely optional.

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
}
2727
],
2828
"require": {
29-
"php": ">=5.3.0"
29+
"php": ">=7.1"
3030
},
3131
"require-dev": {
32-
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
32+
"phpunit/phpunit": "^9.6 || ^7.5"
3333
},
3434
"suggest": {
3535
"ext-pcntl": "For signal handling support when using the StreamSelectLoop"

examples/12-generate-yes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require __DIR__ . '/../vendor/autoload.php';
66

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

1010
// repeat data X times in order to fill around 200 KB
1111
$data = str_repeat($data, round(200000 / strlen($data)));

examples/91-benchmark-ticks.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

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

99
for ($i = 0; $i < $n; ++$i) {
1010
Loop::futureTick(function () { });

examples/92-benchmark-timers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

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

99
for ($i = 0; $i < $n; ++$i) {
1010
Loop::addTimer(0, function () { });

examples/93-benchmark-ticks-delay.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
7+
$ticks = (int) ($argv[1] ?? 1000 * 100);
88
$tick = function () use (&$tick, &$ticks) {
99
if ($ticks > 0) {
1010
--$ticks;

examples/94-benchmark-timers-delay.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
$ticks = isset($argv[1]) ? (int)$argv[1] : 1000 * 100;
7+
$ticks = (int) ($argv[1] ?? 1000 * 100);
88
$tick = function () use (&$tick, &$ticks) {
99
if ($ticks > 0) {
1010
--$ticks;

examples/95-benchmark-memory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
require __DIR__ . '/../vendor/autoload.php';
1515

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

2020
if (!($loop instanceof LoopInterface)) {
2121
Loop::set(new $loop());
2222
}
2323

24-
$r = isset($args['r']) ? (int)$args['r'] : 2;
24+
$r = (int) ($args['r'] ?? 2);
2525

2626
$runs = 0;
2727

phpunit.xml.legacy

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- PHPUnit configuration file with old format for legacy PHPUnit -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
66
bootstrap="vendor/autoload.php"
77
colors="true">
88
<testsuites>

src/ExtEvLoop.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* that provides an interface to `libev` library.
1717
* `libev` itself supports a number of system-specific backends (epoll, kqueue).
1818
*
19-
* This loop is known to work with PHP 5.4 through PHP 8+.
19+
* This loop is known to work with PHP 7.1 through PHP 8+.
2020
*
2121
* @see http://php.net/manual/en/book.ev.php
2222
* @see https://bitbucket.org/osmanov/pecl-ev/overview
@@ -41,12 +41,12 @@ class ExtEvLoop implements LoopInterface
4141
/**
4242
* @var EvIo[]
4343
*/
44-
private $readStreams = array();
44+
private $readStreams = [];
4545

4646
/**
4747
* @var EvIo[]
4848
*/
49-
private $writeStreams = array();
49+
private $writeStreams = [];
5050

5151
/**
5252
* @var bool
@@ -61,7 +61,7 @@ class ExtEvLoop implements LoopInterface
6161
/**
6262
* @var \EvSignal[]
6363
*/
64-
private $signalEvents = array();
64+
private $signalEvents = [];
6565

6666
public function __construct()
6767
{
@@ -138,13 +138,11 @@ public function addTimer($interval, $callback)
138138
{
139139
$timer = new Timer($interval, $callback, false);
140140

141-
$that = $this;
142-
$timers = $this->timers;
143-
$callback = function () use ($timer, $timers, $that) {
141+
$callback = function () use ($timer) {
144142
\call_user_func($timer->getCallback(), $timer);
145143

146-
if ($timers->contains($timer)) {
147-
$that->cancelTimer($timer);
144+
if ($this->timers->contains($timer)) {
145+
$this->cancelTimer($timer);
148146
}
149147
};
150148

src/ExtEventLoop.php

+20-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* that provides an interface to `libevent` library.
1717
* `libevent` itself supports a number of system-specific backends (epoll, kqueue).
1818
*
19-
* This loop is known to work with PHP 5.4 through PHP 8+.
19+
* This loop is known to work with PHP 7.1 through PHP 8+.
2020
*
2121
* @link https://pecl.php.net/package/event
2222
*/
@@ -27,15 +27,15 @@ final class ExtEventLoop implements LoopInterface
2727
private $timerCallback;
2828
private $timerEvents;
2929
private $streamCallback;
30-
private $readEvents = array();
31-
private $writeEvents = array();
32-
private $readListeners = array();
33-
private $writeListeners = array();
34-
private $readRefs = array();
35-
private $writeRefs = array();
30+
private $readEvents = [];
31+
private $writeEvents = [];
32+
private $readListeners = [];
33+
private $writeListeners = [];
34+
private $readRefs = [];
35+
private $writeRefs = [];
3636
private $running;
3737
private $signals;
38-
private $signalEvents = array();
38+
private $signalEvents = [];
3939

4040
public function __construct()
4141
{
@@ -67,8 +67,8 @@ public function __destruct()
6767
$this->timerEvents->detach($timer);
6868
}
6969

70-
$this->readEvents = array();
71-
$this->writeEvents = array();
70+
$this->readEvents = [];
71+
$this->writeEvents = [];
7272
}
7373

7474
public function addReadStream($stream, $listener)
@@ -85,9 +85,7 @@ public function addReadStream($stream, $listener)
8585

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

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

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

112108
public function removeReadStream($stream)
@@ -173,7 +169,7 @@ public function addSignal($signal, $listener)
173169
$this->signals->add($signal, $listener);
174170

175171
if (!isset($this->signalEvents[$signal])) {
176-
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, array($this->signals, 'call'));
172+
$this->signalEvents[$signal] = Event::signal($this->eventBase, $signal, [$this->signals, 'call']);
177173
$this->signalEvents[$signal]->add();
178174
}
179175
}
@@ -239,11 +235,10 @@ private function scheduleTimer(TimerInterface $timer)
239235
*/
240236
private function createTimerCallback()
241237
{
242-
$timers = $this->timerEvents;
243-
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
238+
$this->timerCallback = function ($_, $__, $timer) {
244239
\call_user_func($timer->getCallback(), $timer);
245240

246-
if (!$timer->isPeriodic() && $timers->contains($timer)) {
241+
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
247242
$this->cancelTimer($timer);
248243
}
249244
};
@@ -258,17 +253,15 @@ private function createTimerCallback()
258253
*/
259254
private function createStreamCallback()
260255
{
261-
$read =& $this->readListeners;
262-
$write =& $this->writeListeners;
263-
$this->streamCallback = function ($stream, $flags) use (&$read, &$write) {
256+
$this->streamCallback = function ($stream, $flags) {
264257
$key = (int) $stream;
265258

266-
if (Event::READ === (Event::READ & $flags) && isset($read[$key])) {
267-
\call_user_func($read[$key], $stream);
259+
if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
260+
\call_user_func($this->readListeners[$key], $stream);
268261
}
269262

270-
if (Event::WRITE === (Event::WRITE & $flags) && isset($write[$key])) {
271-
\call_user_func($write[$key], $stream);
263+
if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
264+
\call_user_func($this->writeListeners[$key], $stream);
272265
}
273266
};
274267
}

0 commit comments

Comments
 (0)