Skip to content

Commit

Permalink
优化 compile 逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbur-yu committed Jan 13, 2021
1 parent 35f0059 commit 4f1b497
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Opcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/
namespace WilburYu\HyperfOpcache;

use Exception;
use Symfony\Component\Finder\Finder;
use Throwable;

/**
* Class Opcache.
Expand Down Expand Up @@ -80,26 +80,30 @@ public function compile($force = false): ?array
$files = collect(Finder::create()->in(config('opcache.directories'))
->name('*.php')
->ignoreUnreadableDirs()
->ignoreDotFiles(true)
->ignoreVCS(true)
->notContains('#!/usr/bin/env php')
->exclude(config('opcache.exclude_dirs'))
->files()
->followLinks());

// optimized files
$files->each(function ($file) use (&$compiled) {
$array = explode('/', (string) $file);
$files->each(function ($file) use (&$compiled, $force) {
$file = (string) $file;
$array = explode('/', $file);
$filename = array_pop($array);

if (in_array($filename, config('opcache.exclude_files'), true)) {
return;
}
try {
if (! opcache_is_script_cached((string) $file)) {
opcache_compile_file((string) $file);
if (! opcache_is_script_cached($file)) {
opcache_invalidate($file, $force);
opcache_compile_file($file);
}

++$compiled;
} catch (Exception $e) {
} catch (Throwable $e) {
}
});

Expand Down

0 comments on commit 4f1b497

Please sign in to comment.