diff --git a/core/composer.json b/core/composer.json index 4a109a2..5610a0e 100644 --- a/core/composer.json +++ b/core/composer.json @@ -20,6 +20,7 @@ "twig/twig": "1.12.1", "doctrine/common": "2.3.0", "guzzle/http": "3.1.0", + "guzzle/plugin-async": "3.1.0", "kriswallsmith/assetic": "1.1.0-alpha1", "symfony-cmf/routing": "dev-master#ea4a10", "easyrdf/easyrdf": "0.8.0-beta.1", diff --git a/core/composer.lock b/core/composer.lock index 8715a8e..4f7e1a5 100644 --- a/core/composer.lock +++ b/core/composer.lock @@ -1,5 +1,5 @@ { - "hash": "a8c56a3549ec70f775e4bf795e65a993", + "hash": "ea4e5e5da86989b55eb693856d0a7088", "packages": [ { "name": "doctrine/common", @@ -268,6 +268,55 @@ ] }, { + "name": "guzzle/plugin-async", + "version": "v3.1.0", + "target-dir": "Guzzle/Plugin/Async", + "source": { + "type": "git", + "url": "https://github.com/guzzle/plugin-async", + "reference": "v3.0.7" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/plugin-async/archive/v3.0.7.zip", + "reference": "v3.0.7", + "shasum": "" + }, + "require": { + "guzzle/http": "self.version", + "php": ">=5.3.2" + }, + "time": "2012-12-07 16:45:11", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Plugin\\Async": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle async request plugin", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "plugin" + ] + }, + { "name": "guzzle/stream", "version": "v3.1.0", "target-dir": "Guzzle/Stream", @@ -791,7 +840,7 @@ "symfony/http-kernel": ">=2.1,<2.3-dev", "symfony/routing": ">=2.1,<2.3-dev" }, - "time": "2013-01-21 20:33:16", + "time": "2013-01-24 16:09:01", "type": "library", "extra": { "branch-alias": { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 5f540a3..81d1277 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -8,8 +8,8 @@ use Drupal\Core\Utility\ModuleInfo; use Drupal\Core\TypedData\Primitive; use Drupal\system\Plugin\block\block\SystemMenuBlock; +use Guzzle\Plugin\Async\AsyncPlugin; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Response; /** * Maximum age of temporary files in seconds. @@ -3726,7 +3726,18 @@ function system_run_automated_cron() { if (($threshold = config('system.cron')->get('threshold.autorun')) > 0 && variable_get('install_task') == 'done') { $cron_last = state()->get('system.cron_last') ?: NULL; if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $threshold)) { - drupal_cron_run(); + // Only execute the request if we can aquire the lock. If this fails then + // another request is already taking care of it and we don't have to + // retry. + if (lock()->acquire('cron_request')) { + // Execute the asynchronous request. This will return immediately with a + // HTTP/1.1 200 OK and X-Guzzle-Async as the singe header. + $url = url('cron/' . state()->get('system.cron_key'), array('absolute' => TRUE)); + $request = drupal_container()->get('http_default_client')->get($url); + $request->addSubscriber(new AsyncPlugin()); + $request->send(); + lock()->release('cron_request'); + } } } } diff --git a/core/vendor/autoload.php b/core/vendor/autoload.php index 5a49ae7..8892bbc 100644 --- a/core/vendor/autoload.php +++ b/core/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit481bddffaf22b51d159ec1b257c2bd7f::getLoader(); +return ComposerAutoloaderInit4221fc054178f7eea0c7d285e1457cc4::getLoader(); diff --git a/core/vendor/composer/autoload_namespaces.php b/core/vendor/composer/autoload_namespaces.php index 54b2551..fda22bc 100644 --- a/core/vendor/composer/autoload_namespaces.php +++ b/core/vendor/composer/autoload_namespaces.php @@ -21,6 +21,7 @@ 'Symfony\\Cmf\\Component\\Routing' => $vendorDir . '/symfony-cmf/routing/', 'Psr\\Log\\' => $vendorDir . '/psr/log/', 'Guzzle\\Stream' => $vendorDir . '/guzzle/stream/', + 'Guzzle\\Plugin\\Async' => $vendorDir . '/guzzle/plugin-async/', 'Guzzle\\Parser' => $vendorDir . '/guzzle/parser/', 'Guzzle\\Http' => $vendorDir . '/guzzle/http/', 'Guzzle\\Common' => $vendorDir . '/guzzle/common/', diff --git a/core/vendor/composer/autoload_real.php b/core/vendor/composer/autoload_real.php index 24c4d51..8cc7a99 100644 --- a/core/vendor/composer/autoload_real.php +++ b/core/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php generated by Composer -class ComposerAutoloaderInit481bddffaf22b51d159ec1b257c2bd7f +class ComposerAutoloaderInit4221fc054178f7eea0c7d285e1457cc4 { private static $loader; @@ -19,9 +19,9 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit481bddffaf22b51d159ec1b257c2bd7f', 'loadClassLoader')); + spl_autoload_register(array('ComposerAutoloaderInit4221fc054178f7eea0c7d285e1457cc4', 'loadClassLoader')); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit481bddffaf22b51d159ec1b257c2bd7f', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit4221fc054178f7eea0c7d285e1457cc4', 'loadClassLoader')); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); diff --git a/core/vendor/composer/installed.json b/core/vendor/composer/installed.json index d272cdb..29549bf 100644 --- a/core/vendor/composer/installed.json +++ b/core/vendor/composer/installed.json @@ -834,207 +834,6 @@ "homepage": "http://symfony.com" }, { - "name": "guzzle/common", - "version": "v3.1.0", - "version_normalized": "3.1.0.0", - "target-dir": "Guzzle/Common", - "source": { - "type": "git", - "url": "git://github.com/guzzle/common.git", - "reference": "v3.1.0" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/common/archive/v3.1.0.zip", - "reference": "v3.1.0", - "shasum": "" - }, - "require": { - "php": ">=5.3.2", - "symfony/event-dispatcher": ">=2.1" - }, - "time": "2013-01-13 05:14:34", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Common": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Common libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "collection", - "common", - "event", - "exception" - ] - }, - { - "name": "guzzle/stream", - "version": "v3.1.0", - "version_normalized": "3.1.0.0", - "target-dir": "Guzzle/Stream", - "source": { - "type": "git", - "url": "https://github.com/guzzle/stream", - "reference": "v3.1.0" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/stream/archive/v3.1.0.zip", - "reference": "v3.1.0", - "shasum": "" - }, - "require": { - "guzzle/common": "self.version", - "php": ">=5.3.2" - }, - "time": "2012-12-07 16:45:11", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Stream": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle stream wrapper component", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "Guzzle", - "component", - "stream" - ] - }, - { - "name": "guzzle/parser", - "version": "v3.1.0", - "version_normalized": "3.1.0.0", - "target-dir": "Guzzle/Parser", - "source": { - "type": "git", - "url": "git://github.com/guzzle/parser.git", - "reference": "v3.1.0" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/parser/archive/v3.1.0.zip", - "reference": "v3.1.0", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "time": "2013-01-12 21:43:21", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Parser": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Interchangeable parsers used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "URI Template", - "cookie", - "http", - "message", - "url" - ] - }, - { - "name": "guzzle/http", - "version": "v3.1.0", - "version_normalized": "3.1.0.0", - "target-dir": "Guzzle/Http", - "source": { - "type": "git", - "url": "git://github.com/guzzle/http.git", - "reference": "v3.1.0" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/http/archive/v3.1.0.zip", - "reference": "v3.1.0", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "guzzle/common": "self.version", - "guzzle/parser": "self.version", - "guzzle/stream": "self.version", - "php": ">=5.3.2" - }, - "time": "2013-01-13 05:09:32", - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Http": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "HTTP libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "Guzzle", - "client", - "curl", - "http", - "http client" - ] - }, - { "name": "symfony/translation", "version": "2.2.x-dev", "version_normalized": "2.2.9999999.9999999-dev", @@ -1510,5 +1309,257 @@ "database", "routing" ] + }, + { + "name": "guzzle/common", + "version": "v3.1.0", + "version_normalized": "3.1.0.0", + "target-dir": "Guzzle/Common", + "source": { + "type": "git", + "url": "git://github.com/guzzle/common.git", + "reference": "v3.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/common/archive/v3.1.0.zip", + "reference": "v3.1.0", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/event-dispatcher": ">=2.1" + }, + "time": "2013-01-13 05:14:34", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Common": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Common libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "collection", + "common", + "event", + "exception" + ] + }, + { + "name": "guzzle/stream", + "version": "v3.1.0", + "version_normalized": "3.1.0.0", + "target-dir": "Guzzle/Stream", + "source": { + "type": "git", + "url": "https://github.com/guzzle/stream", + "reference": "v3.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/stream/archive/v3.1.0.zip", + "reference": "v3.1.0", + "shasum": "" + }, + "require": { + "guzzle/common": "self.version", + "php": ">=5.3.2" + }, + "time": "2012-12-07 16:45:11", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Stream": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle stream wrapper component", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "component", + "stream" + ] + }, + { + "name": "guzzle/parser", + "version": "v3.1.0", + "version_normalized": "3.1.0.0", + "target-dir": "Guzzle/Parser", + "source": { + "type": "git", + "url": "git://github.com/guzzle/parser.git", + "reference": "v3.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/parser/archive/v3.1.0.zip", + "reference": "v3.1.0", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "time": "2013-01-12 21:43:21", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Parser": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Interchangeable parsers used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "URI Template", + "cookie", + "http", + "message", + "url" + ] + }, + { + "name": "guzzle/http", + "version": "v3.1.0", + "version_normalized": "3.1.0.0", + "target-dir": "Guzzle/Http", + "source": { + "type": "git", + "url": "git://github.com/guzzle/http.git", + "reference": "v3.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/http/archive/v3.1.0.zip", + "reference": "v3.1.0", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "guzzle/common": "self.version", + "guzzle/parser": "self.version", + "guzzle/stream": "self.version", + "php": ">=5.3.2" + }, + "time": "2013-01-13 05:09:32", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Http": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "HTTP libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "client", + "curl", + "http", + "http client" + ] + }, + { + "name": "guzzle/plugin-async", + "version": "v3.1.0", + "version_normalized": "3.1.0.0", + "target-dir": "Guzzle/Plugin/Async", + "source": { + "type": "git", + "url": "https://github.com/guzzle/plugin-async", + "reference": "v3.0.7" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/plugin-async/archive/v3.0.7.zip", + "reference": "v3.0.7", + "shasum": "" + }, + "require": { + "guzzle/http": "self.version", + "php": ">=5.3.2" + }, + "time": "2012-12-07 16:45:11", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Plugin\\Async": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle async request plugin", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "plugin" + ] } ] diff --git a/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/AsyncPlugin.php b/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/AsyncPlugin.php new file mode 100644 index 0000000..7edc664 --- /dev/null +++ b/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/AsyncPlugin.php @@ -0,0 +1,88 @@ + 'onBeforeSend', + 'request.exception' => 'onRequestTimeout', + 'request.sent' => 'onRequestSent', + 'curl.callback.progress' => 'onCurlProgress' + ); + } + + /** + * Event used to ensure that progress callback are emitted from the curl handle's request mediator. + * + * @param Event $event + */ + public function onBeforeSend(Event $event) + { + // Ensure that progress callbacks are dispatched + $event['request']->getCurlOptions()->set('progress', true); + } + + /** + * Event emitted when a curl progress function is called. When the amount of data uploaded == the amount of data to + * upload OR any bytes have been downloaded, then time the request out after 1ms because we're done with + * transmitting the request, and tell curl not download a body. + * + * @param Event $event + */ + public function onCurlProgress(Event $event) + { + if (!$event['handle']) { + return; + } + + if ($event['downloaded'] || ($event['uploaded'] || $event['upload_size'] === $event['uploaded'])) { + $event['handle']->getOptions() + ->set(CURLOPT_TIMEOUT_MS, 1) + ->set(CURLOPT_NOBODY, true); + // Timeout after 1ms + curl_setopt($event['handle']->getHandle(), CURLOPT_TIMEOUT_MS, 1); + // Even if the response is quick, tell curl not to download the body + curl_setopt($event['handle']->getHandle(), CURLOPT_NOBODY, true); + } + } + + /** + * Event emitted when a curl exception occurs. Ignore the exception and set a mock response. + * + * @param Event $event + */ + public function onRequestTimeout(Event $event) + { + if ($event['exception'] instanceof CurlException) { + $event['request']->setResponse(new Response(200, array( + 'X-Guzzle-Async' => 'Did not wait for the response' + ))); + } + } + + /** + * Event emitted when a request completes because it took less than 1ms. Add an X-Guzzle-Async header to notify the + * caller that there is no body in the message. + * + * @param Event $event + */ + public function onRequestSent(Event $event) + { + // Let the caller know this was meant to be async + $event['request']->getResponse()->setHeader('X-Guzzle-Async', 'Did not wait for the response'); + } +} diff --git a/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/composer.json b/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/composer.json new file mode 100644 index 0000000..12cd529 --- /dev/null +++ b/core/vendor/guzzle/plugin-async/Guzzle/Plugin/Async/composer.json @@ -0,0 +1,27 @@ +{ + "name": "guzzle/plugin-async", + "description": "Guzzle async request plugin", + "homepage": "http://guzzlephp.org/", + "keywords": ["plugin", "guzzle"], + "license": "MIT", + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "require": { + "php": ">=5.3.2", + "guzzle/http": "self.version" + }, + "autoload": { + "psr-0": { "Guzzle\\Plugin\\Async": "" } + }, + "target-dir": "Guzzle/Plugin/Async", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + } +}