From 6ba1e615468e26ca8380ed272f53b1f13694fe8b Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 3 Mar 2014 13:45:38 +0100 Subject: [PATCH] Reduce connection overhead --- lib/Alchemy/Phrasea/CLI.php | 6 +++++ .../Phrasea/Controller/Admin/Collection.php | 11 ++++++---- .../Connection/ReconnectableConnection.php | 13 +++++------ .../Core/PhraseaCLIExceptionHandler.php | 22 +++++++++++++++++++ www/index_dev.php | 2 ++ 5 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Core/PhraseaCLIExceptionHandler.php diff --git a/lib/Alchemy/Phrasea/CLI.php b/lib/Alchemy/Phrasea/CLI.php index 9698e890c7..9599db358d 100644 --- a/lib/Alchemy/Phrasea/CLI.php +++ b/lib/Alchemy/Phrasea/CLI.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea; use Alchemy\Phrasea\Command\CommandInterface; use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\WebsocketServerServiceProvider; +use Alchemy\Phrasea\Core\PhraseaCLIExceptionHandler; use Alchemy\Phrasea\Exception\RuntimeException; use Symfony\Component\Console; 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\SignalHandlerServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\TaskManagerServiceProvider; +use Symfony\Component\Debug\ErrorHandler; /** * Phraseanet Command Line Application @@ -66,6 +68,10 @@ class CLI extends Application $this->register(new DoctrineMigrationServiceProvider()); $this->bindRoutes(); + + error_reporting(-1); + ErrorHandler::register(); + PhraseaCLIExceptionHandler::register(); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php index 09469e9045..11ee0b31b8 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php @@ -955,12 +955,15 @@ class Collection implements ControllerProviderInterface $success = false; $collection = \collection::get_from_base_id($app, $bas_id); + $prefs = $request->request->get('str'); try { - $domdoc = new \DOMDocument(); - if ($domdoc->loadXML($request->request->get('str'))) { - $collection->set_prefs($domdoc); - $success = true; + if ('' !== trim($prefs)) { + $domdoc = new \DOMDocument(); + if (true === $domdoc->loadXML($prefs)) { + $collection->set_prefs($domdoc); + $success = true; + } } } catch (\Exception $e) { diff --git a/lib/Alchemy/Phrasea/Core/Connection/ReconnectableConnection.php b/lib/Alchemy/Phrasea/Core/Connection/ReconnectableConnection.php index 185a3ad900..f1798856c8 100644 --- a/lib/Alchemy/Phrasea/Core/Connection/ReconnectableConnection.php +++ b/lib/Alchemy/Phrasea/Core/Connection/ReconnectableConnection.php @@ -116,13 +116,8 @@ class ReconnectableConnection implements ConnectionInterface private function tryMethod($method, $args) { try { - set_error_handler(function ($errno, $errstr) { throw new \Exception($errstr, $errno); }); - $ret = call_user_func_array([$this->connection, $method], $args); - restore_error_handler(); - - return $ret; + return call_user_func_array([$this->connection, $method], $args); } catch (\Exception $exception) { - restore_error_handler(); $e = $exception; while ($e->getPrevious() && !$e instanceof \PDOException) { $e = $e->getPrevious(); @@ -133,7 +128,11 @@ class ReconnectableConnection implements ConnectionInterface 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->connect(); diff --git a/lib/Alchemy/Phrasea/Core/PhraseaCLIExceptionHandler.php b/lib/Alchemy/Phrasea/Core/PhraseaCLIExceptionHandler.php new file mode 100644 index 0000000000..83a10f9c52 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/PhraseaCLIExceptionHandler.php @@ -0,0 +1,22 @@ +