What are the performance implications of downloading PHP files via SFTP/SCP for repeated API calls, and how can this be optimized?

Downloading PHP files via SFTP/SCP for repeated API calls can lead to performance issues due to the overhead of establishing a new connection for each call. To optimize this, you can cache the downloaded PHP files locally and include them in your script to avoid the need for repeated downloads.

<?php

// Function to download and cache PHP file
function downloadAndCacheFile($remoteFile, $localFile) {
    // Download file via SFTP/SCP
    // Save downloaded file locally
}

// Check if cached file exists, if not download and cache it
if (!file_exists('cached_file.php')) {
    downloadAndCacheFile('remote_file.php', 'cached_file.php');
}

// Include cached file for API calls
include 'cached_file.php';

// Make API calls using functions from included file
// ...