Requests_Transport_fsockopen::request_multiple() WordPress Method

The WordPress request multiple fsockopen transport method is used to make multiple HTTP requests to multiple hosts using a single connection. This is a performance optimization since it reduces the number of TCP connections that need to be made. It is especially useful when making requests to multiple hosts that are on the same network.

Requests_Transport_fsockopen::request_multiple( array $requests, array $options ) #

Send multiple requests simultaneously


Parameters

$requests

(array)(Required)Request data (array of 'url', 'headers', 'data', 'options') as per Requests_Transport::request

$options

(array)(Required)Global options, see Requests::response() for documentation


Top ↑

Return

(array) Array of Requests_Response objects (may contain Requests_Exception or string responses as well)


Top ↑

Source

File: wp-includes/Requests/Transport/fsockopen.php

	public function request_multiple($requests, $options) {
		$responses = array();
		$class     = get_class($this);
		foreach ($requests as $id => $request) {
			try {
				$handler        = new $class();
				$responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']);

				$request['options']['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$id], $request));
			}
			catch (Requests_Exception $e) {
				$responses[$id] = $e;
			}

			if (!is_string($responses[$id])) {
				$request['options']['hooks']->dispatch('multiple.request.complete', array(&$responses[$id], $id));
			}
		}

		return $responses;
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.