Last active
March 16, 2021 13:26
-
-
Save IlanVivanco/34078e100c7e00014ff7b64ed6b8aef1 to your computer and use it in GitHub Desktop.
Paralelize downloads in order to increase speed over HTTP 1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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