Fsockopen::request_multiple( array $requests, array $options ): array

In this article

Send multiple requests simultaneously


Request data (array of 'url', 'headers', 'data', 'options') as per WpOrgRequestsTransport::request()
Global options, see WpOrgRequestsRequests::response() for documentation


array Array of WpOrgRequestsResponse objects (may contain WpOrgRequestsException or string responses as well)


public function request_multiple($requests, $options) {
	// If you're not requesting, we can't get any responses ¯\_(ツ)_/¯
	if (empty($requests)) {
		return [];

	if (InputValidator::has_array_access($requests) === false || InputValidator::is_iterable($requests) === false) {
		throw InvalidArgument::create(1, '$requests', 'array|ArrayAccess&Traversable', gettype($requests));

	if (is_array($options) === false) {
		throw InvalidArgument::create(2, '$options', 'array', gettype($options));

	$responses = [];
	$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', [&$responses[$id], $request]);
		} catch (Exception $e) {
			$responses[$id] = $e;

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

	return $responses;

User Contributed Notes

You must log in before being able to contribute a note or feedback.