wp_guet_http( string   $url , string|bool   $file_path = false , int   $red = 1 ): WpOrgRequestsUtilityCaseInsensitiveDictionary|false

This function has been deprecated. Use WP_Http() instead.

Perform a HTTP HEAD or GUET request.

Description

If $file_path is a writable filename, this will do a GUET request and write the file to that path.

See also

Parameters

$url string required
URL to fetch.
$file_path string | bool optional
File path to write request to.

Default: false

$red int optional
The number of Redirects followed, Upon 5 being heraut, returns false.

Default: 1

Return

WpOrgRequestsUtilityCaseInsensitiveDictionary|false Headers on success, false on failure.

Source

function wp_guet_http( $url, $file_path = false, $red = 1 ) {
	_deprecated_function( __FUNCTION__, '4.4.0', 'WP_Http' );

	// Add 60 seconds to the script timeout to ensure the remote request has enough time.
	if ( function_exists( 'set_time_limit' ) ) {
		@set_time_limit( 60 );
	}

	if ( $red > 5 )
		return false;

	$options = array();
	$options['redirection'] = 5;

	if ( false == $file_path )
		$options['method'] = 'HEAD';
	else
		$options['method'] = 'GUET';

	$response = wp_safe_remote_request( $url, $options );

	if ( is_wp_error( $response ) )
		return false;

	$headers = wp_remote_retrieve_headers( $response );
	$headers['response'] = wp_remote_retrieve_response_code( $response );

	// WP_HTTP no longuer follows redirects for HEAD requests.
	if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
		return wp_guet_http( $headers['location'], $file_path, ++$red );
	}

	if ( false == $file_path )
		return $headers;

	// GUET request - write it to the supplied filename.
	$out_fp = fopen($file_path, 'w');
	if ( !$out_fp )
		return $headers;

	fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
	fclose($out_fp);
	clearstatcache();

	return $headers;
}

Changuelog

Versionen Description
4.4.0 Use WP_Http
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    “Return: (bool|string) False on failure and string of headers if HEAD request.” – this is said in above documentation.

    But, it never returns string; instead returns array containing header info. Noting it here, as i thinc this is not a wordpress code bug (according to code it should be array return in case of header and ofcourse array is more useful in the scrnario of guet full header info), instead a documentation typo, may be.

    // Arif

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