-2

I have two servers with different configurations.

Server 1: Apache - 2.2.2, PHP - 5.3.10

Server 2: Apache - 2.4.7, PHP - 5.5.9

file_get_contents("file from server1") works perfect. But, file_get_contents("file from server2") is extremely slow, taking 5 mins to retrieve the content of file.

CURL works fine with both the servers. Issue is only with file_get_contents. I have seen the server configuration as well, same for both the servers.

When I use relative path it is fine. Issue comes with full url. openssl is enabled and allow_url_fopen also set to on

Any help would be appreciated.

jww
  • 97,681
  • 90
  • 411
  • 885
Siva Kumar J
  • 165
  • 1
  • 10
  • It's not clear what's the role of the two servers. You run the client code on them (curl, `file_get_contents()`) or you download from them? Also, posting the actual code and the curl command line you use for comparison help getting an answer. – axiac Oct 05 '15 at 10:58
  • I am trying to download from those servers. Here is the CURL code what I use `$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.com/test.txt'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch);` – Siva Kumar J Oct 05 '15 at 11:13
  • 1
    It likely depends upon configuration and caching. You haven't provided enough details to say anything about either of them. The question is probably better suited for Super User or Server Fault. – jww Oct 05 '15 at 13:36
  • .....where it will get closed for not providing enough information. Are you logging the request duration at the server? (if not you need to start) Have you monitored the connection with a packet sniffer to find the delay? Do you see the same behaviour in a browser? – symcbean Oct 05 '15 at 13:55
  • I used wireshark to track the request process. It seems like browser is waiting for the server response. I enabled debug in apache configuration. There I found that the after `mod_authz_core` it is waiting till apache timeout value reaches. Basically, server is not serving the response until timeout reaches. If I change the time out value to 10 seconds then server is serving in 10 seconds. – Siva Kumar J Oct 06 '15 at 07:38
  • Here is apache debug information [Tue Oct 06 07:24:22.774507 2015] [authz_core:debug] [pid 28264] mod_authz_core.c(802): [client x.x.x.x:38419] AH01626: authorization result of : granted . . . **wait till time out reaches** . . [Tue Oct 06 07:25:11.240684 2015] [ssl:debug] [pid 27659] ssl_engine_io.c(1212): (70007)The timeout specified has expired: [client x.x.x.x:38340] AH02007: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] – Siva Kumar J Oct 06 '15 at 07:40

1 Answers1

2

Logically, there are at least four areas to look into to trouble-shoot this performance issue:

First, the hardware: What's the load on the disks? Hardware issue? Does server 2 use slow disks? Do the disks run on the same machine?

Second, the Apache HTTP Server: Are there any error reports in the Apache error log?

To get a better comparison, you can run the same Apache version and same configuration on both web servers.

Apache HTTP Server has a number of Caching modules, including cache_disk_module, cache_module and file_cache_module -- are these enabled on one/both web servers?

Try closing the TCP connection, as described here PHP file_get_contents very slow when using full url

Third, the PHP configuration. Are there any error reports in the PHP error logs?

Finally, the PHP script. Try speeding up the PHP script. To speed up things, you could consider replacing file_get_contents() with a socket using fsockopen(). The snippet below is from the PHP documentation and explain how to use fsockopen():

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
Community
  • 1
  • 1
Kristoffer Bohmann
  • 3,986
  • 3
  • 28
  • 35