I have website, wich loads config files (5-15 per 1 webpage) from remote ftp servers (linux proftpd).
When user opens (refresh) only one web-page - everything is fine, page renders to fast (~100 milliseconds). When user open 4-6 tabs one by one (~1 sec delay between opening tabs) on web browser, avg 1-3 web-pages renders to fast, but 4-6 pages it too sloooow (up to 60 seconds or more).
I find bottleneck: this is ftp_get() php function, that freeze to time of timeout set in ftp_connect() when getting files from ftp. Only ftp_get() freeze web-page rendering.
public function getConfigViaFtp($config_name)
{
$handle = fopen('php://temp', 'r+');
ftp_fget($this->getFtpConnectionStream(), $handle, $config_name, FTP_ASCII);
rewind($handle);
return stream_get_contents($handle);
}
I am ssh to remote ftp server and run ftptop to look on the connections when page freeze. proftpd have only one connection with COMMAND 'RETR'.
ftp_get always succesfuly get first (sometimes up to 5 files) file from ftp, but another files always empty (but exists and not empty on the ftp server) and ftp_get timeouts on this files.
I try to:
ob_start();
$result = ftp_get($this->getFtpConnectionStream(), 'php://output', $config_name, FTP_ASCII);
$data = ob_get_contents();
ob_end_clean();
try ftp_pasv()
but nothing :( ftp_get()
and web-page still freeze a lot of time and doesn't load contents of files in end of each web-page.
Whats wrong? proftpd settings (default) or something else?