How can the PHP code be modified to handle multiple servers with different ports?

To handle multiple servers with different ports in PHP, you can modify the code to include the server's port number as part of the server address when making requests. This way, you can specify the port for each server individually and ensure the requests are sent to the correct server.

<?php
$servers = [
    'server1' => 'http://example.com:8080',
    'server2' => 'http://example.org:9090'
];

foreach ($servers as $server => $url) {
    $response = file_get_contents($url);
    echo "Response from $server: $response\n";
}
?>