Azure上的SimplePie不解析https提要


SimplePie on Azure not parsing https feeds

我使用编译版本的SimplePie 1.4.2 (GitHub上的最后一个标记版本)来聚合一些rss/atom提要(如果需要,下面的代码)。

它在几个基于linux的web主机上工作得很好,但是当我把它上传到Azure应用程序服务时,只有http提要显示正确,但https不。

为什么会这样?在web应用程序上没有特定的设置,在两个环境中都使用PHP 5.6。通过http或https访问azure web应用程序没有区别。

谢谢大家!


<?php
date_default_timezone_set('Europe/Rome');
set_time_limit(0);
header('Content-Type: application/rss+xml; charset=UTF-8');
require_once('SimplePie.compiled.php');
[...]
echo '<?xml version="1.0" encoding="UTF-8"?>'; 
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><?php echo $feedtitle; ?></title>
<atom:link href="<?php echo $feedlink; ?>" rel="self" type="application/rss+xml" />
<link><?php echo $feedhome; ?></link>
<description><?php echo $feeddesc; ?></description>
<?php
$feed = new SimplePie();
$feed->set_feed_url($feeds);
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
foreach($feed->get_items() as $item) {
    ?>
    <item>
        <title><?php echo $item->get_title(); ?></title>
        <link><?php echo $item->get_permalink(); ?></link>
        <guid><?php echo $item->get_permalink(); ?></guid>
        <pubDate><?php echo $item->get_date('D, d M Y H:i:s T'); ?></pubDate>
        <dc:creator><?php if ($author = $item->get_author()) { echo $author->get_name()." at "; }; ?><?php if ($feed_title = $item->get_feed()->get_title()) {echo $feed_title;}?></dc:creator>
        <description><![CDATA[<?php echo $item->get_content(); ?>]]></description>
    </item>
    <?
};
?>
</channel>
</rss>

对于'https' url不起作用,因为SimplePie利用cURL来发出http请求,而对于https请求,cURL需要验证主机或对等证书。

您可以尝试下面的代码片段来绕过验证。

$simplePie = new SimplePie();
$simplePie->set_curl_options(
    array(
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_SSL_VERIFYPEER => false
    )
);
下面是类似的场景:https://github.com/simplepie/simplepie/pull/407