-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from bryanlatten/file-opcache
File-based opcache: ENV variable
- Loading branch information
Showing
10 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8 | ||
FROM behance/docker-nginx:8.9 | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php/7.0/fpm/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20151012 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8 | ||
FROM behance/docker-nginx:8.9 | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php/7.1/fpm/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20160303 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8 | ||
FROM behance/docker-nginx:8.9 | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php/7.2/fpm/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20170718 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8 | ||
FROM behance/docker-nginx:8.9 | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php/7.3/fpm/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20180731 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8-alpine | ||
FROM behance/docker-nginx:8.9-alpine | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php7/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20180731 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM behance/docker-nginx:8.8 | ||
FROM behance/docker-nginx:8.9 | ||
LABEL maintainers="Behance Team <[email protected]>" | ||
|
||
# Set TERM to suppress warning messages. | ||
|
@@ -23,6 +23,7 @@ ENV CONF_PHPFPM=/etc/php/7.4/fpm/php-fpm.conf \ | |
PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ | ||
PHP_OPCACHE_INTERNED_STRINGS_BUFFER=16 \ | ||
PHP_OPCACHE_MAX_WASTED_PERCENTAGE=5 \ | ||
PHP_OPCACHE_ENABLE_CLI=1 \ | ||
PHP_ENGINE_VERSION=20190902 \ | ||
CFG_APP_DEBUG=1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Sends all eligible files into PHP's opcode cache before server startup | ||
*/ | ||
$LOGPREFIX = '[opcache]'; | ||
$MEMORY_USAGE_WARNING_PERCENTAGE = 85; | ||
$app_root = getenv('APP_ROOT'); | ||
|
||
if (!$app_root) { | ||
echo("${LOGPREFIX} cannot preload, APP_ROOT is empty"); | ||
return; | ||
} | ||
|
||
echo "${LOGPREFIX} preloading from ${app_root}\n"; | ||
$start_time = microtime(true); | ||
|
||
[ $count, $success, $failure ] = compileFiles($app_root); | ||
|
||
$end_time = microtime(true); | ||
$elapsed = ($end_time - $start_time); | ||
$elapsed = round($elapsed, 3); | ||
|
||
echo "${LOGPREFIX} preloaded: processed ${count} files - ${success} successful / ${failure} failed, in ${elapsed} seconds\n"; | ||
|
||
$opcache_status = opcache_get_status(false); | ||
$memory_usage = $opcache_status['memory_usage'] ?? []; | ||
|
||
if (empty($memory_usage)) { | ||
echo "${LOGPREFIX} error: no memory reported\n"; | ||
return; | ||
} | ||
|
||
$free_memory = $memory_usage['free_memory'] ?? 0; | ||
$wasted_memory = $memory_usage['wasted_memory'] ?? 0; | ||
$used_memory = $memory_usage['used_memory'] ?? 0; | ||
|
||
$memory_total = $wasted_memory + $free_memory + $used_memory; | ||
$memory_consumed = $used_memory + $wasted_memory; | ||
$percentage_used = ($memory_consumed / $memory_total) * 100; | ||
$percentage_used = round($percentage_used, 2); | ||
|
||
if ($percentage_used >= $MEMORY_USAGE_WARNING_PERCENTAGE) { | ||
echo "${LOGPREFIX} warning: ${percentage_used}% memory usage, consider raising PHP_OPCACHE_MEMORY_CONSUMPTION env variable\n"; | ||
} else { | ||
echo "${LOGPREFIX} complete: ${percentage_used}% memory utilized\n"; | ||
} | ||
|
||
function compileFiles($input) { | ||
$directory = new RecursiveDirectoryIterator($input); | ||
$fullTree = new RecursiveIteratorIterator($directory); | ||
|
||
$phpunit_filter = '/^(?:(?!test).)*\.php$/i'; // Removes PHPUnit-style filenames (ie. calculatortest.php) | ||
|
||
$all_files = new RegexIterator($fullTree, $phpunit_filter, RecursiveRegexIterator::GET_MATCH); | ||
$success = 0; | ||
$failure = 0; | ||
$results = []; | ||
|
||
foreach($all_files as $file) { | ||
if (@opcache_compile_file($file[0])) { | ||
++$success; | ||
} else { | ||
++$failure; | ||
} | ||
} | ||
|
||
$count = $success + $failure; | ||
|
||
return [ $count, $success, $failure ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters