Skip to content

Timeouts

Michael Beckwith edited this page Mar 14, 2024 · 4 revisions

Adjust configuration settings to increase timeout threshold.

Adjust HttpClientInterface arguments

Accurate as of WP Search with Algolia 2.7.x

This documnetation a work in progress.

WP Search with Algolia makes use of the HttpClientInterface provided by Algolia's PHP client.

With that, we have the algolia_http_client_options filter available for usage to pass arguments to a new CurlHttpClient instance. Default of an empty array.

With this filter, you can pass an array of valid key/value pairs that are meant to be used with curl_setopt() function calls. The cURL handle will already be managed, this just needs the settings to adjust.

function my_algolia_timeout_increase( $args ) {
	// Increase timeout to 3 minutes.
	$args['CURLOPT_TIMEOUT'] = 180;
	return $args;
}
add_filter( 'algolia_http_client_options', 'my_algolia_timeout_increase' );

See https://curl.se/libcurl/c/CURLOPT_TIMEOUT.html specifically for CURLOPT_TIMEOUT.

See https://curl.haxx.se/libcurl/c/curl_easy_setopt.html for a list of all available curl_setopt() arguments.

Adjust Algolia SearchClient configuration.

Available with WP Search with Algolia 2.8.0 or later.

If you are finding that you are having timeout issues at the SearchClient level of indexing, you can adjust the timeout settings with the following filter.

See https://www.algolia.com/doc/api-reference/api-methods/configuring-timeouts/ for more information.

All values returned with the be in seconds. Values will be cast to integers before being applied to a SearchClient config. All are optional

<?php
function wds_algolia_custom_searchclient_config( $config ) {
	$config['connectTimeout'] = 5;  // default: 2
	$config['readTimeout']    = 60; // default: 30
	$config['writeTimeout']   = 60; // default: 30

	return $config;
}
add_filter( 'algolia_custom_search_config', 'wds_algolia_custom_searchclient_config' );