Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP file_get_contents is slow and return 500 Internal Server Error
    primarykey
    data
    text
    <p>I'm trying to read rss of a news agency site and get several options of all news to save in my database. so i used php functions as file_get_contents or cURl but it takes about a minute to get content of site and analyze it for seperating that parts of news I want.</p> <p>This is a part of my code that I get datails of news from rss:</p> <pre><code>$rss = new DOMDocument(); $rss-&gt;load('http://isna.ir/fa/Sports/feed'); $feed = array(); foreach ($rss-&gt;getElementsByTagName('item') as $node) { $item = array ( 'title' =&gt; $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue, 'category' =&gt; $node-&gt;getElementsByTagName('category')-&gt;item(0)-&gt;nodeValue, 'link' =&gt; $node-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue, 'date' =&gt; $node-&gt;getElementsByTagName('pubDate')-&gt;item(0)-&gt;nodeValue, ); array_push($feed, $item); } $title = str_replace(' &amp; ', ' &amp;amp; ', $feed[0]['title']); $link = $feed[0]['link']; $category = $feed[0]['category']; $date = date('l F d, Y', strtotime($feed[0]['date'])); </code></pre> <p>And in this part I use link of news to get a photo from original news page :</p> <pre><code>$context = stream_context_create(array('http' =&gt; array('header'=&gt;'Connection: close'))); $f = explode("news", $link); $photo_link = $f[0]. 'photo' .$f[1]; $ff = file_get_contents($photo_link, false, $context); $f1 = explode('&lt;div class="news-image"&gt;', $ff); $f2 = explode('&lt;h1', $f1[1]); $f3 = explode('href="', $f2[0]); $f4 = explode('"&gt;', $f3[1]); $image = $f4[0]; echo '&lt;img src="' .$image. '"&gt;&lt;/img&gt;'; </code></pre> <p>And this is the result most of the times:</p> <pre><code>Warning: file_get_contents(http://isna.ir/fa/photo/92040301515/مدافع-تیم-ملی-آلمان-از-فوتبال-خداحافظی-کرد) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /opt/lampp/htdocs/example8/reader.php </code></pre> <p>I used the cURL functions too, but not much better result obtained!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload