<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ベンチ | ウダ2Blog</title>
	<atom:link href="https://uda2.com/blog/tag/%E3%83%99%E3%83%B3%E3%83%81/feed/" rel="self" type="application/rss+xml" />
	<link>https://uda2.com/blog</link>
	<description>大阪でフリーランスとしてWEB制作している管理人が気になった技術をメモったり、作ったツールの紹介などを綴っているブログです。</description>
	<lastBuildDate>Mon, 04 May 2015 19:26:35 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>simplexml_load_fileとsimplexml_load_stringの速度比較</title>
		<link>https://uda2.com/blog/simplexml_load_file_string/</link>
					<comments>https://uda2.com/blog/simplexml_load_file_string/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Mon, 04 May 2015 18:34:29 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ベンチ]]></category>
		<guid isPermaLink="false">http://uda2.com/blog/?p=1935</guid>

					<description><![CDATA[<p>外部サイトのRSSを読む処理をする際に専用の関数simplexml_load_fileを使っていた。 混雑するサイトを考慮してタイムアウト時間、待機時間、再試行回数を含めた関数を作った。 function h_simpl</p>
The post <a href="https://uda2.com/blog/simplexml_load_file_string/">simplexml_load_fileとsimplexml_load_stringの速度比較</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>外部サイトのRSSを読む処理をする際に専用の関数simplexml_load_fileを使っていた。<br />
混雑するサイトを考慮してタイムアウト時間、待機時間、再試行回数を含めた関数を作った。<br />
<span id="more-1935"></span></p>
<pre><code>function h_simplexml_load_file($url,$timeout=3,$delay=1,$repeat=5) {
	ini_set('default_socket_timeout',$timeout);
	for ($i = 0; !($rss = @simplexml_load_file($url)) && $i &lt; $repeat; ++$i) {
		sleep($delay);
		if ($i == $repeat-1) {
			return false;
		}
	}
	return $rss;
}</code></pre>
<p>ふと、simplexml_load_fileとfile_get_contentsしてからsimplexml_load_stringするのってどっちが早いのだろうと考え試してみた。</p>
<pre><code>function h_simplexml_load_file2($url,$timeout=3,$delay=1,$repeat=5) {
	if (!($buffer = h_file_get_contents($url,$timeout,$delay,$repeat))) return false;
	if (!($rss = @simplexml_load_string($buffer))) return false;
	return $rss;
}
function h_file_get_contents($url,$timeout=3,$delay=1,$repeat=5) {
	ini_set('default_socket_timeout',$timeout);
	for ($i = 0; !($rss = @file_get_contents($url)) && $i &lt; $repeat; ++$i) {
		sleep($delay);
		if ($i == $repeat-1) {
			return false;
		}
	}
	return $rss;
}</code></pre>
<p>適当に某人気アイドルグループのブログ52サイトで調査してみた。</p>
<p>h_simplexml_load_file（simplexml_load_file）<br />
1回目：44.2637<br />
2回目：44.1838<br />
3回目：44.4204</p>
<p>h_simplexml_load_file2（file_get_contentsしてからsimplexml_load_string）<br />
1回目：38.863<br />
2回目：38.7857<br />
3回目：39.8881</p>
<p>意外な事にfile_get_contentsしてからsimplexml_load_stringの方が早かった。</p>The post <a href="https://uda2.com/blog/simplexml_load_file_string/">simplexml_load_fileとsimplexml_load_stringの速度比較</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/simplexml_load_file_string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
