Reduce connection overhead

This commit is contained in:
Romain Neutron
2014-03-03 13:45:38 +01:00
parent 8cf73891c0
commit 6ba1e61546
5 changed files with 43 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea;
use Alchemy\Phrasea\Command\CommandInterface; use Alchemy\Phrasea\Command\CommandInterface;
use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\WebsocketServerServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\WebsocketServerServiceProvider;
use Alchemy\Phrasea\Core\PhraseaCLIExceptionHandler;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Console; use Symfony\Component\Console;
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
@@ -23,6 +24,7 @@ use Alchemy\Phrasea\Core\CLIProvider\LessBuilderServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\PluginServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\PluginServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\SignalHandlerServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\SignalHandlerServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\TaskManagerServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\TaskManagerServiceProvider;
use Symfony\Component\Debug\ErrorHandler;
/** /**
* Phraseanet Command Line Application * Phraseanet Command Line Application
@@ -66,6 +68,10 @@ class CLI extends Application
$this->register(new DoctrineMigrationServiceProvider()); $this->register(new DoctrineMigrationServiceProvider());
$this->bindRoutes(); $this->bindRoutes();
error_reporting(-1);
ErrorHandler::register();
PhraseaCLIExceptionHandler::register();
} }
/** /**

View File

@@ -955,12 +955,15 @@ class Collection implements ControllerProviderInterface
$success = false; $success = false;
$collection = \collection::get_from_base_id($app, $bas_id); $collection = \collection::get_from_base_id($app, $bas_id);
$prefs = $request->request->get('str');
try { try {
$domdoc = new \DOMDocument(); if ('' !== trim($prefs)) {
if ($domdoc->loadXML($request->request->get('str'))) { $domdoc = new \DOMDocument();
$collection->set_prefs($domdoc); if (true === $domdoc->loadXML($prefs)) {
$success = true; $collection->set_prefs($domdoc);
$success = true;
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -116,13 +116,8 @@ class ReconnectableConnection implements ConnectionInterface
private function tryMethod($method, $args) private function tryMethod($method, $args)
{ {
try { try {
set_error_handler(function ($errno, $errstr) { throw new \Exception($errstr, $errno); }); return call_user_func_array([$this->connection, $method], $args);
$ret = call_user_func_array([$this->connection, $method], $args);
restore_error_handler();
return $ret;
} catch (\Exception $exception) { } catch (\Exception $exception) {
restore_error_handler();
$e = $exception; $e = $exception;
while ($e->getPrevious() && !$e instanceof \PDOException) { while ($e->getPrevious() && !$e instanceof \PDOException) {
$e = $e->getPrevious(); $e = $e->getPrevious();
@@ -133,7 +128,11 @@ class ReconnectableConnection implements ConnectionInterface
return call_user_func_array([$this->connection, $method], $args); return call_user_func_array([$this->connection, $method], $args);
} }
if ((false !== strpos($exception->getMessage(), 'MySQL server has gone away')) || (false !== strpos($exception->getMessage(), 'errno=32 Broken pipe'))) { if (
(false !== strpos($exception->getMessage(), 'MySQL server has gone away'))
|| (false !== strpos($exception->getMessage(), 'Error while sending QUERY packet'))
|| (false !== strpos($exception->getMessage(), 'errno=32 Broken pipe'))
) {
$this->connection->close(); $this->connection->close();
$this->connection->connect(); $this->connection->connect();

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
class PhraseaCLIExceptionHandler extends SymfonyExceptionHandler
{
public function handle(\Exception $exception)
{
throw $exception;
}
}

View File

@@ -14,6 +14,8 @@ use Symfony\Component\Debug\ErrorHandler;
require_once __DIR__ . "/../lib/autoload.php"; require_once __DIR__ . "/../lib/autoload.php";
error_reporting(-1);
ErrorHandler::register(); ErrorHandler::register();
$environment = Application::ENV_DEV; $environment = Application::ENV_DEV;