Search code examples
phpazurerssazure-web-app-servicesimplepie

SimplePie on Azure not parsing https feeds


I'm using a compiled version of SimplePie 1.4.2 (the last tagged version on GitHub) to aggregate some rss/atom feeds (code below if needed).

It works well on a couple of linux-based web hosts, but when I upload it to Azure app services only the http feeds display correctly, but https don't.

Why it happens? No specific settings set on web app, using PHP 5.6 in both environments. No differences accessing azure web app through http or https.

Thanks everybody!


<?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>

Solution

  • It dosen't work for 'https' urls because the SimplePie leverages cURL to make http requests, and for https requests, the cURL requires verify the host or peer certificate.

    You can try the following code snippet to bypass the verification.

    $simplePie = new SimplePie();
    $simplePie->set_curl_options(
        array(
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_SSL_VERIFYPEER => false
        )
    );
    

    Here is the similar scenario at https://github.com/simplepie/simplepie/pull/407