Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8c1375

Browse files
jaymecdgordalina
authored andcommitted
compile file into opcache (#64)
* compile file into opcache * update readme * Fix indent
1 parent ef4db98 commit f8c1375

4 files changed

Lines changed: 96 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ You have some useful commands that you can use
9898
apcu:regexp:delete Deletes all APCu key matching a regexp
9999
apcu:sma:info Show APCu shared memory allocation information
100100
opcache
101+
opcache:compile:scripts Compile scripts from path to the opcode cache
101102
opcache:configuration Get configuration information about the cache
102103
opcache:invalidate:scripts Remove scripts from the opcode cache
103104
opcache:reset Resets the contents of the opcode cache

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"php": ">=5.5.9",
77
"symfony/console": "~3.0|~4.0",
88
"symfony/dependency-injection": "~3.0|~4.0",
9+
"symfony/finder": "~3.0|~4.0",
910
"symfony/process": "~3.0|~4.0",
1011
"symfony/yaml": "~3.0|~4.0",
1112
"psr/log": "~1.0",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of CacheTool.
5+
*
6+
* (c) Samuel Gordalina <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace CacheTool\Command;
13+
14+
use Symfony\Component\Console\Helper\Table;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Finder\Finder;
19+
20+
class OpcacheCompileScriptsCommand extends AbstractCommand
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
protected function configure()
26+
{
27+
$this
28+
->setName('opcache:compile:scripts')
29+
->setDescription('Compile scripts from path to the opcode cache')
30+
->addArgument('path', InputArgument::REQUIRED)
31+
->setHelp('');
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected function execute(InputInterface $input, OutputInterface $output)
38+
{
39+
$this->ensureExtensionLoaded('Zend OPcache');
40+
$path = $input->getArgument('path');
41+
42+
$info = $this->getCacheTool()->opcache_get_status(true);
43+
44+
if ($info === false) {
45+
throw new \RuntimeException('opcache_get_status(): No Opcache status info available. Perhaps Opcache is disabled via opcache.enable or opcache.enable_cli?');
46+
}
47+
48+
$splFiles = $this->prepareFileList($path);
49+
50+
$table = new Table($output);
51+
$table
52+
->setHeaders(array(
53+
'Compiled',
54+
'Filename'
55+
))
56+
->setRows($this->processFilelist($splFiles))
57+
;
58+
59+
$table->render();
60+
}
61+
62+
protected function processFileList($splFiles)
63+
{
64+
$list = array();
65+
66+
foreach ($splFiles as $file) {
67+
$list[] = array(
68+
$this->getCacheTool()->opcache_compile_file($file->getRealPath()),
69+
$file->getRealPath()
70+
);
71+
}
72+
73+
return $list;
74+
}
75+
76+
/**
77+
* @param string $path
78+
*
79+
* @return \Traversable|\SplFileInfo[]
80+
*/
81+
private function prepareFileList($path)
82+
{
83+
return Finder::create()
84+
->files()
85+
->in($path)
86+
->name('*.php')
87+
->notPath('/Tests/')
88+
->notPath('/tests/')
89+
->ignoreUnreadableDirs()
90+
->ignoreDotFiles(true)
91+
->ignoreVCS(true);
92+
}
93+
}

src/CacheTool/Console/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function getDefaultCommands()
9393
$commands[] = new CacheToolCommand\OpcacheStatusCommand();
9494
$commands[] = new CacheToolCommand\OpcacheStatusScriptsCommand();
9595
$commands[] = new CacheToolCommand\OpcacheInvalidateScriptsCommand();
96+
$commands[] = new CacheToolCommand\OpcacheInvalidateScriptsCommand();
9697
}
9798

9899
$commands[] = new CacheToolCommand\StatCacheClearCommand();

0 commit comments

Comments
 (0)