Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
20 changes: 12 additions & 8 deletions src/CacheTool/Adapter/FastCGI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
71 changes: 71 additions & 0 deletions src/CacheTool/Command/ApcRegexpDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of CacheTool.
*
* (c) Samuel Gordalina <[email protected]>
*
* 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("<comment>APC key <info>{$key['info']}</info> was deleted</comment>");
} else {
$output->writeln("<comment>APC key <info>{$key['info']}</info> could not be deleted.</comment>");
}
}
$cpt ++;
}
if ($output->isVerbose()) {
$output->writeln("<comment>APC key <info>{$cpt}</info> keys treated.</comment>");
}
return 1;
}
}
1 change: 1 addition & 0 deletions src/CacheTool/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down