看起来PHP getimagesize()导致了一些关于https的问题。会发生的事情是,当我通过https调用它时,在页面加载之前,存在等于apache conf文件中的超时设置的延迟。例如,如果我将apache超时值设置为12秒,则在执行之前调用会挂起12秒。如果我通过http访问相同的脚本,一切正常。我在下面写了一些调试代码:
<?php
echo "The start time is " . date("h:i:sa");
echo "<br>";
$img_url = url()."/assets/img/logo/45.jpg";
print $img_url;
echo "<br>";
echo "The time before getimagesize() is " . date("h:i:sa");
echo "<br>";
$img_dimen = getimagesize($img_url);
print_r($img_dimen);
echo "<br>";
echo "The time after getimagesize() is " . date("h:i:sa");
echo "<br>";
function url(){
return sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME'],
dirname($_SERVER['REQUEST_URI'])
);
}
?>
https上的输出是:
The start time is 07:02:17pm
https://myserver.mydomain.com/assets/img/logo/45.jpg
The time before getimagesize() is 07:02:17pm
Array ( [0] => 226 [1] => 78 [2] => 2 [3] => width="226" height="78" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
The time after getimagesize() is 07:02:30pm
可以看出,完成getimagesize()调用需要13秒。
http输出是:
The start time is 07:05:30pm
https://myserver.mydomain.com/assets/img/logo/45.jpg
The time before getimagesize() is 07:05:30pm
Array ( [0] => 226 [1] => 78 [2] => 2 [3] => width="226" height="78" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
The time after getimagesize() is 07:05:30pm
apache.conf中的超时设置为12.如果我更改此超时值,则https所用的时间会相应更改。图像的大小只有32KB。
我的虚拟主机看起来像:
<VirtualHost *:443>
ServerName myserver.mydomain.com
ServerAlias myserver.mydomain.com
DirectoryIndex index.php
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /root/apache-keys/mycert.crt
SSLCertificateKeyFile /root/apache-keys/mykey.key
SSLCertificateChainFile /root/apache-keys/mybundle.crt
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
vhost conf文件包含*:80的部分,其详细信息与上述相同。此服务器上托管有其他站点(不同子域的不同vhost)。每个vhost遵循与此相同的模式(*:443,*:80),它们都在不同的.conf文件中。其中大多数都有自签名证书,而其中一个与该站点共享证书(证书是通配符证书)。将证书更改为自签名证书也无济于事。也没有禁用共享相同证书的其他站点。
error.log显示以下一些其他网站:
[Wed Jan 03 08:07:03.067875 2018] [ssl:warn] [pid 1328] AH01909: RSA certificate configured for othersite1.mydomain.com:443 does NOT include an ID which matches the server name
[Wed Jan 03 08:07:03.068056 2018] [ssl:warn] [pid 1328] AH01909: RSA certificate configured for othersite2.mydomain.com:443 does NOT include an ID which matches the server name
除此之外,error.log中没有其他错误。
我已经在ssllabs.com上检查了该网站,并且证书没有问题。
apache2ctl -S的输出显示该站点是端口80和端口443的默认服务器。我已经尝试禁用所有其他站点,但这种情况发生了。
更多细节: Apache版本是2.4.7。 PHP版本是5.6.30 操作系统是Ubuntu 14.04
非常感谢任何帮助。如果需要任何其他信息,请与我们联系。我真的很想了解为什么getimagesize会在返回https之前导致超时。