Skip to content

Commit 674b9b7

Browse files
authoredMar 17, 2021
Merge pull request #49 from DarkGhostHunter/master
Added PHP 8.0 support.
2 parents 19829a8 + 9791086 commit 674b9b7

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed
 

‎.github/workflows/php.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
strategy:
1212
fail-fast: true
1313
matrix:
14-
php: [7.4]
14+
php: [7.4, 8.0]
1515
dependency-version: [prefer-lowest, prefer-stable]
1616

1717
name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
1818

1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v1
21+
uses: actions/checkout@v2
2222

2323
- name: Setup PHP
2424
uses: shivammathur/setup-php@v2
@@ -28,7 +28,7 @@ jobs:
2828
coverage: xdebug
2929

3030
- name: Cache dependencies
31-
uses: actions/cache@v1
31+
uses: actions/cache@v2
3232
with:
3333
path: ~/.composer/cache/files
3434
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
@@ -47,5 +47,5 @@ jobs:
4747
COVERALLS_SERVICE_NAME: github
4848
run: |
4949
rm -rf composer.* vendor/
50-
composer require cedx/coveralls
51-
vendor/bin/coveralls build/logs/clover.xml
50+
composer require php-coveralls/php-coveralls
51+
vendor/bin/php-coveralls

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Braden Collum - Unsplash (UL) #9HI8UJMSdZA](https://images.unsplash.com/photo-14
1010

1111
Get the best options to keep your application fast as ever, with just one line.
1212

13-
This package generates a [PHP 7.4 preloading](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.preload) script from your Opcache statistics automatically. No need to hack your way in.
13+
This package generates a [PHP preloading](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.preload) script from your Opcache statistics automatically. No need to hack your way in.
1414

1515
> If you're looking for preloading your Laravel project, check [Laraload](https://github.com/DarkGhostHunter/Laraload).
1616
@@ -42,8 +42,8 @@ This package generates a [PHP 7.4 preloading](https://www.php.net/manual/en/opca
4242

4343
## Requirements
4444

45-
* PHP 7.4.3 or later.
46-
* [Opcache enabled](https://www.php.net/manual/en/book.opcache.php) (`ext-opcache`).
45+
* PHP 7.4.3, PHP 8.0 or later.
46+
* [Opcache & Preloading enabled](https://www.php.net/manual/en/book.opcache.php) (`ext-opcache`).
4747
* Composer Autoloader (optional).
4848

4949
## Installation
@@ -73,13 +73,13 @@ This will automatically gather Opcache statistics, and write an optimized `prelo
7373
├── PreloaderCall.php
7474
└── preload.php
7575

76-
Once generated, tell PHP to use this file as a preloader at startup in your `php.ini`.
76+
Once generated, tell PHP to use this file as a preloader at start up in your `php.ini`.
7777

7878
```ini
7979
opcache.preload=/www/app/preload.php
8080
```
8181

82-
Restart your PHP process that's using Opcache, and that's all, you're good.
82+
Once the script is generated, **you're encouraged to restart your PHP process** (or server, in some cases) to pick up the generated preload script. Only generating the script [is not enough](https://www.php.net/manual/en/opcache.preloading.php).
8383

8484
> If you use Preloader when Opcache is disabled or without hits, you will get an Exception.
8585

‎composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^7.4",
23+
"php": "^7.4||^8.0",
2424
"ext-json": "*",
2525
"symfony/finder": "^4.3||^5.0.5"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^9.0"
28+
"phpunit/phpunit": "^9.3"
2929
},
3030
"autoload": {
3131
"psr-4": {
@@ -38,7 +38,7 @@
3838
}
3939
},
4040
"scripts": {
41-
"test": "vendor/bin/phpunit"
41+
"test": "vendor/bin/phpunit --coverage-clover build/logs/clover.xml"
4242
},
4343
"config": {
4444
"sort-packages": true

‎src/PreloaderCompiler.php

+23-8
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,34 @@ public function compile() : string
9191
protected function scriptRealPath()
9292
{
9393
// @codeCoverageIgnoreStart
94-
// We will try to create a dummy file and just then get the real path of it.
95-
// After getting the real path, we will delete it and return the path. If
96-
// we can't, then we will just return the output path string as-it-is.
97-
if (! touch($this->writeTo)) {
98-
return $this->writeTo;
94+
// We need to get the real path of the preloader file. To do that, we
95+
// will check if the file already exists, and if not, create a dummy
96+
// one. If that "touch" fails, we will return whatever path we got.
97+
if (file_exists($this->writeTo)) {
98+
return realpath($this->writeTo);
9999
}
100+
101+
return $this->touchAndGetRealPath();
100102
// @codeCoverageIgnoreEnd
103+
}
101104

102-
$path = realpath($this->writeTo);
105+
/**
106+
* Creates a dummy file and returns the real path of it, if possible.
107+
*
108+
* @return false|string
109+
*/
110+
protected function touchAndGetRealPath()
111+
{
112+
// @codeCoverageIgnoreStart
113+
$path = $this->writeTo;
103114

104-
unlink($this->writeTo);
115+
if (touch($this->writeTo)) {
116+
$path = $this->writeTo;
117+
unlink($this->writeTo);
118+
}
105119

106-
return $path;
120+
return $path ?: $this->writeTo;
121+
// @codeCoverageIgnoreEnd
107122
}
108123

109124
/**

0 commit comments

Comments
 (0)
Please sign in to comment.