Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 1d2dae6

Browse files
committed
Integrate file cache into the cache scenario
1 parent 2a7f364 commit 1d2dae6

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

lib/php/libsdk/SDK/Build/PGO/Abstracts/PHP.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ abstract class PHP
1111
{
1212
protected $php_root;
1313
protected $php_ext_root;
14+
protected $opcache_file_cache;
15+
protected $id;
1416

1517
protected function setupPaths()
1618
{
@@ -23,6 +25,9 @@ protected function setupPaths()
2325
} else {
2426
$this->php_ext_root = $this->php_root;
2527
}
28+
if ("cache" == $this->scenario) {
29+
$this->opcache_file_cache = SDKConfig::getTmpDir() . DIRECTORY_SEPARATOR . $this->id;
30+
}
2631
}
2732

2833
/* TODO Might be improved. */
@@ -147,6 +152,11 @@ public function getIniFilename()
147152
}
148153
}
149154

155+
/* Special handling, otherwise it'll need functionality to extrapolate ini values. */
156+
if ("cache" == $this->scenario) {
157+
$tpl_vars[$this->conf->buildTplVarName("php", "opcache", "file_cache")] = $this->opcache_file_cache;
158+
}
159+
150160
$this->conf->processTplFile(
151161
$this->getIniTplFilename(),
152162
$ret,
@@ -214,5 +224,13 @@ public function exec(string $php_cmd, string $args = NULL, array $extra_env = ar
214224

215225
return proc_close($p);
216226
}
227+
228+
public function getIdString(): string
229+
{
230+
return $this->getVersion() . "-"
231+
. SDKConfig::getCurrentCrtName() . "-"
232+
. ($this->isThreadSafe() ? "ts" : "nts") . "-"
233+
. ($this->is64bit() ? "x64" : "x86");
234+
}
217235
}
218236

lib/php/libsdk/SDK/Build/PGO/PHP/CLI.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public function __construct(PGOConfig $conf)
1616
{
1717
$this->conf = $conf;
1818
$this->scenario = $conf->getScenario();
19+
// Don't do that, it'll be a recursive dependency.
20+
// Once we need to train CLI, we'll need to split
21+
// a new class, this one is a utility class.
22+
//$this->id = $this->getIdString();
1923

2024
$this->setupPaths();
2125
}

lib/php/libsdk/SDK/Build/PGO/PHP/FCGI.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class FCGI extends Abstracts\PHP implements Interfaces\PHP
1212
{
13+
use FileOps;
14+
1315
protected $conf;
1416
protected $is_tcp;
1517

@@ -22,6 +24,7 @@ public function __construct(PGOConfig $conf, bool $is_tcp)
2224
$this->conf = $conf;
2325
$this->is_tcp = $is_tcp;
2426
$this->scenario = $conf->getScenario();
27+
$this->id = $this->getIdString();
2528

2629
$this->setupPaths();
2730
}
@@ -64,6 +67,13 @@ public function up() : void
6467
{
6568
echo "Starting PHP FCGI.\n";
6669

70+
if ("cache" == $this->scenario) {
71+
if (file_exists($this->opcache_file_cache)) {
72+
$this->rm($this->opcache_file_cache);
73+
}
74+
mkdir($this->opcache_file_cache);
75+
}
76+
6777
$exe = $this->getExeFilename();
6878
$ini = $this->getIniFilename();
6979
$host = $this->conf->getSectionItem("php", "fcgi", "host");
@@ -82,6 +92,10 @@ public function up() : void
8292
/* Give some time, it might be slow on PGI enabled proc. */
8393
sleep(3);
8494

95+
/*while(false !== ($s = fread($pipes[2], 1024))) {
96+
echo "$s";
97+
}*/
98+
8599
$c = proc_close($p);
86100

87101
if ($c) {
@@ -99,6 +113,11 @@ public function down(bool $force = false) : void
99113

100114
exec("taskkill /f /im php-cgi.exe >nul 2>&1");
101115

116+
/* XXX Add cleanup interface. */
117+
if ("cache" == $this->scenario) {
118+
$this->rm($this->opcache_file_cache);
119+
}
120+
102121
echo "PHP FCGI stopped.\n";
103122
}
104123
}

pgo/tpl/php/php-7.3-pgo-nts-cache.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,8 @@ opcache.enable=1
993993
;opcache.enable_cli=1
994994
opcache.error_log = PHP_SDK_PGO_PHP_ERROR_LOG
995995
opcache.log_verbosity_level = 2
996+
opcache.file_cache=PHP_SDK_PGO_PHP_OPCACHE_FILE_CACHE
997+
opcache.file_cache_fallback=1
996998

997999
;;;;;;;;;;;;;;;;;;;
9981000
; Module Settings ;

pgo/tpl/php/php-7.3-pgo-ts-cache.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,8 @@ opcache.enable=1
993993
;opcache.enable_cli=1
994994
opcache.error_log = PHP_SDK_PGO_PHP_ERROR_LOG
995995
opcache.log_verbosity_level = 2
996+
opcache.file_cache=PHP_SDK_PGO_PHP_OPCACHE_FILE_CACHE
997+
opcache.file_cache_fallback=1
996998

997999
;;;;;;;;;;;;;;;;;;;
9981000
; Module Settings ;

0 commit comments

Comments
 (0)