From b98849c7a2d54a0e60dcf7b9aaa08ad40b74d01c Mon Sep 17 00:00:00 2001 From: DarkGhosthunter Date: Tue, 16 Mar 2021 22:50:00 -0300 Subject: [PATCH 1/4] Added tests for PHP 8.0 --- .github/workflows/php.yml | 10 +++++----- composer.json | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 870d6b8..538d95e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 @@ -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') }} @@ -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 diff --git a/composer.json b/composer.json index f240434..85cc344 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -38,7 +38,7 @@ } }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/phpunit --coverage-clover build/logs/clover.xml" }, "config": { "sort-packages": true From a5c15377111dc7f4c7bee6333474b1218ef0ce3f Mon Sep 17 00:00:00 2001 From: DarkGhosthunter Date: Tue, 16 Mar 2021 23:01:58 -0300 Subject: [PATCH 2/4] Fixed touch-file procedure to get real path of files. --- src/PreloaderCompiler.php | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/PreloaderCompiler.php b/src/PreloaderCompiler.php index 537a440..1688ab7 100644 --- a/src/PreloaderCompiler.php +++ b/src/PreloaderCompiler.php @@ -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 } /** From 74fde6b74b1bfde588f6649238487ee1244a8b80 Mon Sep 17 00:00:00 2001 From: DarkGhosthunter Date: Tue, 16 Mar 2021 23:07:11 -0300 Subject: [PATCH 3/4] Added requirements. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f16ee2f..65eded8 100644 --- a/README.md +++ b/README.md @@ -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). @@ -42,7 +42,7 @@ This package generates a [PHP 7.4 preloading](https://www.php.net/manual/en/opca ## Requirements -* PHP 7.4.3 or later. +* PHP 7.4.3, PHP 8.0 or later. * [Opcache enabled](https://www.php.net/manual/en/book.opcache.php) (`ext-opcache`). * Composer Autoloader (optional). From 9791086127831a70285773b3fa2063ee1cbfda30 Mon Sep 17 00:00:00 2001 From: DarkGhosthunter Date: Tue, 16 Mar 2021 23:10:35 -0300 Subject: [PATCH 4/4] Added clarification about PHP restart. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 65eded8..2223f46 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ This package generates a [PHP preloading](https://www.php.net/manual/en/opcache. ## Requirements * PHP 7.4.3, PHP 8.0 or later. -* [Opcache enabled](https://www.php.net/manual/en/book.opcache.php) (`ext-opcache`). +* [Opcache & Preloading enabled](https://www.php.net/manual/en/book.opcache.php) (`ext-opcache`). * Composer Autoloader (optional). ## Installation @@ -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.