Skip to content

Commit

Permalink
Merge pull request #49 from DarkGhostHunter/master
Browse files Browse the repository at this point in the history
Added PHP 8.0 support.
  • Loading branch information
DarkGhostHunter committed Mar 17, 2021
2 parents 19829a8 + 9791086 commit 674b9b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4]
php: [7.4, 8.0]
dependency-version: [prefer-lowest, prefer-stable]

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

steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -28,7 +28,7 @@ jobs:
coverage: xdebug

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -47,5 +47,5 @@ jobs:
COVERALLS_SERVICE_NAME: github
run: |
rm -rf composer.* vendor/
composer require cedx/coveralls
vendor/bin/coveralls build/logs/clover.xml
composer require php-coveralls/php-coveralls
vendor/bin/php-coveralls
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Braden Collum - Unsplash (UL) #9HI8UJMSdZA](https://images.unsplash.com/photo-14

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

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.
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.

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

## Requirements

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

## Installation
Expand Down Expand Up @@ -73,13 +73,13 @@ This will automatically gather Opcache statistics, and write an optimized `prelo
├── PreloaderCall.php
└── preload.php

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

```ini
opcache.preload=/www/app/preload.php
```

Restart your PHP process that's using Opcache, and that's all, you're good.
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).

> If you use Preloader when Opcache is disabled or without hits, you will get an Exception.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
}
],
"require": {
"php": "^7.4",
"php": "^7.4||^8.0",
"ext-json": "*",
"symfony/finder": "^4.3||^5.0.5"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand All @@ -38,7 +38,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit --coverage-clover build/logs/clover.xml"
},
"config": {
"sort-packages": true
Expand Down
31 changes: 23 additions & 8 deletions src/PreloaderCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,34 @@ public function compile() : string
protected function scriptRealPath()
{
// @codeCoverageIgnoreStart
// We will try to create a dummy file and just then get the real path of it.
// After getting the real path, we will delete it and return the path. If
// we can't, then we will just return the output path string as-it-is.
if (! touch($this->writeTo)) {
return $this->writeTo;
// We need to get the real path of the preloader file. To do that, we
// will check if the file already exists, and if not, create a dummy
// one. If that "touch" fails, we will return whatever path we got.
if (file_exists($this->writeTo)) {
return realpath($this->writeTo);
}

return $this->touchAndGetRealPath();
// @codeCoverageIgnoreEnd
}

$path = realpath($this->writeTo);
/**
* Creates a dummy file and returns the real path of it, if possible.
*
* @return false|string
*/
protected function touchAndGetRealPath()
{
// @codeCoverageIgnoreStart
$path = $this->writeTo;

unlink($this->writeTo);
if (touch($this->writeTo)) {
$path = $this->writeTo;
unlink($this->writeTo);
}

return $path;
return $path ?: $this->writeTo;
// @codeCoverageIgnoreEnd
}

/**
Expand Down

0 comments on commit 674b9b7

Please sign in to comment.