Skip to content

Instantly share code, notes, and snippets.

@IlanVivanco
Last active March 16, 2021 13:26
Show Gist options
  • Save IlanVivanco/34078e100c7e00014ff7b64ed6b8aef1 to your computer and use it in GitHub Desktop.
Save IlanVivanco/34078e100c7e00014ff7b64ed6b8aef1 to your computer and use it in GitHub Desktop.
Paralelize downloads in order to increase speed over HTTP 1.1
<?php
/**
* Paralelize download test
*/
add_filter( 'wp_get_attachment_url', 'iv_parallelize_hostnames', 10, 2 );
function iv_parallelize_hostnames( $url, $id ) {
$hostname = iv_get_hostname( $url );
$url = str_replace( parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ), $hostname, $url);
return $url;
}
function iv_get_hostname( $name ) {
$subdomains = array(
'www.domain.com',
'ww1.domain.com',
'ww2.domain.com',
'ww3.domain.com',
);
$host = abs( crc32( basename( $name ) ) % count( $subdomains ) );
$hostname = $subdomains[ $host ];
return $hostname;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment