diff --git a/composer.json b/composer.json index 5104998..bb6fa88 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "symfony/yaml": "~2.1", "psr/log": "~1.0", "monolog/monolog": "~1.1", - "ebernhardson/fastcgi": "0.1.*" + "adoy/fastcgi-client": "dev-master" }, "license": "MIT", "authors": [ diff --git a/src/CacheTool/Adapter/FastCGI.php b/src/CacheTool/Adapter/FastCGI.php index a9a4996..0870c26 100644 --- a/src/CacheTool/Adapter/FastCGI.php +++ b/src/CacheTool/Adapter/FastCGI.php @@ -12,8 +12,8 @@ namespace CacheTool\Adapter; use CacheTool\Code; -use EBernhardson\FastCGI\Client; -use EBernhardson\FastCGI\CommunicationException; +use Adoy\FastCGI\Client; +use Adoy\FastCGI\ForbiddenException as CommunicationException; class FastCGI extends AbstractAdapter { @@ -42,8 +42,11 @@ public function __construct($host = null, $tempDir = null) $this->client = new Client($host, $port); } else { // socket - $this->client = new Client($host); + $this->client = new Client('unix://' . $host, -1); } + $this->client->setReadWriteTimeout(60 * 1000); + $this->client->setPersistentSocket(false); + $this->client->setKeepAlive(true); } /** @@ -75,13 +78,14 @@ protected function request(Code $code) 'SCRIPT_FILENAME' => $file, ); - $this->client->request($environment, ''); - $response = $this->client->response(); + try { + $response = $this->client->request($environment, ''); + } catch (CommunicationException $e) { + $this->client->close(); + $response = $this->client->request($environment, ''); + } $this->logger->debug(sprintf('FastCGI: Response: %s', json_encode($response))); - // lets close every request - $this->client->close(); - @unlink($file); return $response; } catch (CommunicationException $e) { diff --git a/src/CacheTool/Command/ApcRegexpDeleteCommand.php b/src/CacheTool/Command/ApcRegexpDeleteCommand.php new file mode 100644 index 0000000..6023379 --- /dev/null +++ b/src/CacheTool/Command/ApcRegexpDeleteCommand.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CacheTool\Command; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class ApcRegexpDeleteCommand extends AbstractCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('apc:regexp:delete') + ->setDescription('Deletes all APC key matching a regexp') + ->addArgument('regexp', InputArgument::REQUIRED) + ->setHelp(''); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->ensureExtensionLoaded('apc'); + + $regexp = $input->getArgument('regexp'); + + $user = $this->getCacheTool()->apc_cache_info('user'); + + $keys = array(); + foreach ($user['cache_list'] as $key) { + $string = $key['info']; + if (preg_match('|' . $regexp . '|', $string)) { + $keys[] = $key; + } + } + $cpt = 0; + $table = $this->getHelper('table'); + $table->setHeaders(array('Key', 'TTL', )); + $table->setRows($keys); + $table->render($output); + foreach ($keys as $key) { + $success = $this->getCacheTool()->apc_delete($key['info']); + if ($output->isVerbose()) { + if ($success) { + $output->writeln("APC key {$key['info']} was deleted"); + } else { + $output->writeln("APC key {$key['info']} could not be deleted."); + } + } + $cpt ++; + } + if ($output->isVerbose()) { + $output->writeln("APC key {$cpt} keys treated."); + } + return 1; + } +} \ No newline at end of file diff --git a/src/CacheTool/Console/Application.php b/src/CacheTool/Console/Application.php index e1ece30..93faf19 100644 --- a/src/CacheTool/Console/Application.php +++ b/src/CacheTool/Console/Application.php @@ -69,6 +69,7 @@ protected function getDefaultCommands() $commands[] = new CacheToolCommand\ApcKeyFetchCommand(); $commands[] = new CacheToolCommand\ApcKeyStoreCommand(); $commands[] = new CacheToolCommand\ApcSmaInfoCommand(); + $commands[] = new CacheToolCommand\ApcRegexpDeleteCommand(); $commands[] = new CacheToolCommand\OpcacheConfigurationCommand(); $commands[] = new CacheToolCommand\OpcacheResetCommand();