Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1594,3 +1594,32 @@ function get_image_versions() {

return $img_versions;
}

/**
* Function to get httpcode or port occupancy info.
*
* @param string $url url to get info about.
* @param int $port The port to check.
* @param bool $port_info Return port info or httpcode.
* @param mixed $auth Send http auth with passed value if not false.
*
* @return bool|int port occupied or httpcode.
*/
function get_curl_info( $url, $port = 80, $port_info = false, $auth = false ) {

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_HEADER, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_PORT, $port );
if ( $auth ) {
curl_setopt( $ch, CURLOPT_USERPWD, $auth );
}
curl_exec( $ch );
if ( $port_info ) {
return empty( curl_getinfo( $ch, CURLINFO_PRIMARY_IP ) );
}

return curl_getinfo( $ch, CURLINFO_HTTP_CODE );
}