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\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();
}
/**

View File

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

View File

@@ -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();

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";
error_reporting(-1);
ErrorHandler::register();
$environment = Application::ENV_DEV;