<?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>icez network &#187; PHP Coding</title>
	<atom:link href="http://www.icez.net/blog/topics/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.icez.net/blog</link>
	<description>Technical Blog by icez network</description>
	<lastBuildDate>Mon, 30 Jan 2012 17:31:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>0104 &#124; ปุ่มอัพโหลดรูปเข้า upic.me ด่วนทันใจ</title>
		<link>http://www.icez.net/blog/721/quick-upic-me-upload-button</link>
		<comments>http://www.icez.net/blog/721/quick-upic-me-upload-button#comments</comments>
		<pubDate>Sun, 11 Jul 2010 08:24:05 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[upicme]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=721</guid>
		<description><![CDATA[คุณสมบัติ - upload รูปได้ทุก format ที่ upic.me รองรับ ขนาดใหญ่ได้ถึง 2MB - เลือกอัพได้ทีละหลายๆ รูปเหมือนหน้าแรก upic.me ด้วย - มีสถานะการ upload ขึ้นตลอดการอัพ และจะหายไปเองเมื่ออัพเสร็จ - อัพเสร็จ code ขึ้นในกล่องข้อความทันที ไม่ต้องก๊อปวาง - ปรับแต่งหน้าตา สีสันของปุ่มได้ตามสะดวก (ส่วนแก้ไขข้อความ จะทำ version ถัดไปครับ) - เอาไปใช้กันได้ฟรีๆ ไม่ต้องแปะ link กลับ ไม่ต้องแปะเครดิตใดๆ ทั้งสิ้น - ไม่เปลือง bandwidth ของ host ด้วย เพราะอัพตรงเข้ามาที่ server ของ upic.me เลย ถ้างงยังไงลองดูตัวอย่าง code ด้านล่างได้เลยครับ &#60;script type=&#34;text/javascript&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>คุณสมบัติ</p>
<p>- upload รูปได้ทุก format ที่ upic.me รองรับ ขนาดใหญ่ได้ถึง 2MB<br />
- เลือกอัพได้ทีละหลายๆ รูปเหมือนหน้าแรก upic.me ด้วย<br />
- มีสถานะการ upload ขึ้นตลอดการอัพ และจะหายไปเองเมื่ออัพเสร็จ<br />
- อัพเสร็จ code ขึ้นในกล่องข้อความทันที ไม่ต้องก๊อปวาง<br />
- ปรับแต่งหน้าตา สีสันของปุ่มได้ตามสะดวก (ส่วนแก้ไขข้อความ จะทำ version ถัดไปครับ)<br />
- เอาไปใช้กันได้ฟรีๆ ไม่ต้องแปะ link กลับ ไม่ต้องแปะเครดิตใดๆ ทั้งสิ้น<br />
- ไม่เปลือง bandwidth ของ host ด้วย เพราะอัพตรงเข้ามาที่ server ของ upic.me เลย</p>
<p>ถ้างงยังไงลองดูตัวอย่าง code ด้านล่างได้เลยครับ</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://upic.me/js/embedupload.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
upic_target <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;targetelement&quot;</span><span style="color: #339933;">;</span>
upic_type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;resulttype&quot;</span><span style="color: #339933;">;</span>
upic_buttoncss <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;appendcss&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>upic_target => จะให้เอา code ไปแปะที่ช่องไหน<br />
upic_type => รูปแบบ code ที่แปะ มี htmlfull / htmlthumb / bbfull / bbthumb (ถ้าไม่ระบุ จะถือว่าเป็น bbthumb ครับ)<br />
upic_buttoncss => css เสริมสำหรับข้อความในปุ่ม เผื่ออยากแก้สีแก้รูปแบบ ใส่ไปได้เลยครับ (การใส่สี รองรับ code แบบ #<a href="http://search.twitter.com/search?q=%23abcdef" rel="nofollow" target="_blank" title="Search Twitter for &quot;abcdef&quot;">abcdef</a> เท่านั้นนะครับ)</p>
<p>ส่วน uploadprogress จะมีประมาณนี้ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
<span style="color: #cc00cc;">#upic_uploader</span><span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#upic_uploadprogress</span><span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressWrapper</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressContainer</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dotted</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressName</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>margin-<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>float<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressBarStatus</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span>text-align<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #993333;">red</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#B50000</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFEBEB</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #993333;">green</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#DDF0DD</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EBFFEB</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">solid</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#CEE2F2</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F0F5FF</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressBarInProgress</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.progressBarComplete</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.progressBarError</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>width<span style="color: #00AA00;">:</span><span style="color: #933;">0%</span><span style="color: #00AA00;">;</span>height<span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span>margin-<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressBarComplete</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">;</span>visibility<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.progressBarError</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>background-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>visibility<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>(พอดีมันผ่าน compressor มาหลายรอบ code เลยดูยากหน่อย ขออภัยด้วยครับ)<br />
ถ้าอยากแก้ไขหน้าตาสีสันยังไง สามารถ copy code ด้านบนไปแก้ไข แล้วใส่ต่อจาก script ได้เลยครับ</p>
<p><span id="more-721"></span></p>
<p>.<br />.<br />
<hr />.<br />.</p>
<p>ตัวอย่าง code นี้สำหรับแปะในบอร์ด SMF ไฟล์ Post.template.php ได้ทันที</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://upic.me/js/embedupload.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
upic_target <span style="color: #339933;">=</span> document.<span style="color: #660066;">postmodify</span>.<span style="color: #660066;">message</span><span style="color: #339933;">;</span>
upic_type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bbthumb&quot;</span><span style="color: #339933;">;</span>
upic_buttoncss <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;color:#000000;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>อันด้านล่างนี้สำหรับ discuz</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://upic.me/js/embedupload.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
upic_target <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;postmessage&quot;</span><span style="color: #339933;">;</span>
upic_type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bbthumb&quot;</span><span style="color: #339933;">;</span>
upic_buttoncss <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;color:#000000;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>=======================<br />
update 2010-08-07 :: custom function สำหรับแทรก code เข้าพวก wysiwyg editor ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://upic.me/js/embedupload.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
upic_target <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;postmessage&quot;</span><span style="color: #339933;">;</span>
upic_type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bbthumb&quot;</span><span style="color: #339933;">;</span>
upic_buttoncss <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;color:#000000;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> upic_custom<span style="color: #009900;">&#40;</span>urlshow<span style="color: #339933;">,</span> urlfull<span style="color: #339933;">,</span> urlthumb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">// do anything here </span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>ตัวอย่างด้านล่างสำหรับ SMF 2.0 ขึ้นไปครับ รองรับการทำงานของ WYSIWYG editor เรียบร้อย</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://upic.me/js/embedupload.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
upic_target <span style="color: #339933;">=</span> document.<span style="color: #660066;">postmodify</span>.<span style="color: #660066;">message</span><span style="color: #339933;">;</span>
upic_type <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bbthumb&quot;</span><span style="color: #339933;">;</span>
upic_buttoncss  <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;color:#000000;&quot;</span><span style="color: #339933;">;</span>
upic_buttontext <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Select Images &lt;span class=<span style="color: #000099; font-weight: bold;">\&quot;</span>buttonSmall<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;(2 MB Max)&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> upic_custom<span style="color: #009900;">&#40;</span>urlshow<span style="color: #339933;">,</span> urlfull<span style="color: #339933;">,</span> urlthumb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>oEditorHandle_message.<span style="color: #660066;">bRichTextEnabled</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
oEditorHandle_message.<span style="color: #660066;">insertText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> urlshow <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> urlthumb <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> border=<span style="color: #000099; font-weight: bold;">\&quot;</span>0<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
upic_target.<span style="color: #660066;">value</span> <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;[url=&quot;</span><span style="color: #339933;">+</span>urlshow<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;][img]&quot;</span><span style="color: #339933;">+</span>urlthumb<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;[/img][/url]&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/721/quick-upic-me-upload-button/feed</wfw:commentRss>
		<slash:comments>100</slash:comments>
		</item>
		<item>
		<title>0098 &#124; ปิดงาน admission 2553</title>
		<link>http://www.icez.net/blog/633/%e0%b8%9b%e0%b8%b4%e0%b8%94%e0%b8%87%e0%b8%b2%e0%b8%99-admission-2553</link>
		<comments>http://www.icez.net/blog/633/%e0%b8%9b%e0%b8%b4%e0%b8%94%e0%b8%87%e0%b8%b2%e0%b8%99-admission-2553#comments</comments>
		<pubDate>Fri, 07 May 2010 15:25:17 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[IP Network]]></category>
		<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[admission]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[internet]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=633</guid>
		<description><![CDATA[ปีนี้พิเศษนิดนึงที่ admissions.mxphone.com และเว็บประกาศผลในเครือ bodinzone ทั้งหมด จะยิงมายัง server เดียวเพื่อทดสอบประสิทธิภาพระบบ cloud computing ครับ (แหม่ ใช้คำซะอินเทรนด์) เอาจริงๆ มันก็ไม่เชิง cloud หรอก แค่เปลี่ยนระบบจัดการข้อมูลใหม่นิดหน่อยเพื่อให้แก้ไขระบบได้สะดวกขึ้น และเสี่ยงต่อการถูกโจมตีจนระบบล่มใช้งานไม่ได้ (DDoS) น้อยลง เนื่องจากการเข้าใช้งานเป็นไปในลักษณะนั้น ผลงานรอบนี้ ขอยกความดีความชอบให้ @rtsp ได้เลยครับ ส่วนความผิดพลาดทั้งหลายผมขอน้อมรับไว้เอง เนื่องด้วยยังอ่อนประสบการณ์เรื่องนี้พอดี T_T ทำให้ระบบร่วงไปประมาณ 30 นาที (ช่วง 17.30 &#8211; 18.00 น.) (มีเวลาเตรียมงาน นับเป็นชั่วโมงก็ราวๆ 4-5 ชั่วโมง แทบไม่ได้ทดสอบอะไรระบบใหม่นี้เลย) แต่ดูแล้ว ผลเป็นที่น่าพอใจ และปีหน้าไม่พลาดแล้วครับ cloud computing จงเจริญ สถิติ: ปริมาณ bandwidth peak 11.6 Mbps เมื่อ [...]]]></description>
			<content:encoded><![CDATA[<p>ปีนี้พิเศษนิดนึงที่ admissions.mxphone.com และเว็บประกาศผลในเครือ bodinzone ทั้งหมด<br />
จะยิงมายัง server เดียวเพื่อทดสอบประสิทธิภาพระบบ cloud computing ครับ (แหม่ ใช้คำซะอินเทรนด์)</p>
<p>เอาจริงๆ มันก็ไม่เชิง cloud หรอก แค่เปลี่ยนระบบจัดการข้อมูลใหม่นิดหน่อยเพื่อให้แก้ไขระบบได้สะดวกขึ้น<br />
และเสี่ยงต่อการถูกโจมตีจนระบบล่มใช้งานไม่ได้ (DDoS) น้อยลง เนื่องจากการเข้าใช้งานเป็นไปในลักษณะนั้น</p>
<p>ผลงานรอบนี้ ขอยกความดีความชอบให้ @<a href="https://twitter.com/rtsp">rtsp</a> ได้เลยครับ ส่วนความผิดพลาดทั้งหลายผมขอน้อมรับไว้เอง<br />
เนื่องด้วยยังอ่อนประสบการณ์เรื่องนี้พอดี T_T ทำให้ระบบร่วงไปประมาณ 30 นาที (ช่วง 17.30 &#8211; 18.00 น.)<br />
(มีเวลาเตรียมงาน นับเป็นชั่วโมงก็ราวๆ 4-5 ชั่วโมง แทบไม่ได้ทดสอบอะไรระบบใหม่นี้เลย)</p>
<p><a href="http://upic.me/e63ek" target="_blank"><img border="0" src="http://upic.me/i/pf/9dvwc.png"></a></p>
<p>แต่ดูแล้ว ผลเป็นที่น่าพอใจ และปีหน้าไม่พลาดแล้วครับ cloud computing จงเจริญ</p>
<p>สถิติ:<br />
ปริมาณ bandwidth peak 11.6 Mbps เมื่อ 18.05 น.โดยประมาณ (แทบจะทันทีที่ระบบกลับมาใช้ได้)<br />
ปริมาณการร้องขอเข้าใช้งานสูงสุด ณ เวลานั้น 1200 ครั้ง ต่อวินาที โดยประมาณ<br />
CPU ช่วงจังหวะสูงสุดใช้ประมาณ 3 Core เต็มๆ (เทียบจาก Core 2 Quad ความเร็ว 2.53 GHz)<br />
RAM ใช้ไปประมาณ 2GB</p>
<p>ข้อมูลเชิงเทคนิค<br />
Web Server: lighttpd 1.4.19<br />
Server-Side Scripting: PHP 5.2.6<br />
Database: MySQL 5.0.51<br />
IDC: <a href="http://www.servenet.co.th">ServeNet</a></p>
<p>ปีหน้าเอา atom server มารันดีมั้ยเนี่ย :D</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/633/%e0%b8%9b%e0%b8%b4%e0%b8%94%e0%b8%87%e0%b8%b2%e0%b8%99-admission-2553/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>0061 &#124; PHP simple object cache</title>
		<link>http://www.icez.net/blog/111/php-simple-object-cache</link>
		<comments>http://www.icez.net/blog/111/php-simple-object-cache#comments</comments>
		<pubDate>Tue, 02 Jun 2009 16:32:51 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimize]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=111</guid>
		<description><![CDATA[ระบบ cache มาอีกแล้ว เอ๊อกๆ คราวนี้เป็น object cache ครับ ไม่ใช่ cache ทั้งหน้าแบบคราวก่อน &#60;?php $_cachetime = 3600; $_cacheroot = '/path/to/cache/'; function cacheget&#40;$key&#41; &#123; global $_cachetime, $_cacheroot; $_cachename = sprintf&#40;'%x', crc32&#40;$key&#41;&#41;; $_cachefolder = $_cacheroot.substr&#40;$_cachename,0,2&#41;.'/'; $_cachefile = $_cachefolder.$_cachename; if &#40;file_exists&#40;$_cachefile&#41; &#38;&#38; &#40;filemtime&#40;$_cachefile&#41; &#62; time&#40;&#41; - $_cachetime &#124;&#124; &#40;file_exists&#40;$_cachefile.'.lock'&#41; &#38;&#38; time&#40;&#41; - filemtime&#40;$_cachefile.'.lock'&#41; &#60; 120&#41;&#41;&#41; &#123; return unserialize&#40;file_get_contents&#40;$_cachefile&#41;&#41;; &#125; return [...]]]></description>
			<content:encoded><![CDATA[<p>ระบบ cache มาอีกแล้ว เอ๊อกๆ<br />
คราวนี้เป็น object cache ครับ ไม่ใช่ cache ทั้งหน้าแบบคราวก่อน</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$_cachetime</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3600</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_cacheroot</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/cache/'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> cacheget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$_cachetime</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%x'</span><span style="color: #339933;">,</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefolder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">.</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$_cachetime</span> <span style="color: #339933;">||</span> 
		<span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.lock'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.lock'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> cachelock<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%x</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefolder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">.</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">,</span><span style="color: #208080;">0777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">touch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.lock'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> cacheset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%x'</span><span style="color: #339933;">,</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefolder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cacheroot</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$_cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">.</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">,</span><span style="color: #208080;">0777</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.lock'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>วิธีติดตั้ง: </p>
<p>include ไฟล์ไปบนสุดเลย แก้ตัวแปร $_cacheroot กับ $_cachetime ด้วยนะครับ<br />
chmod 777 folder ตามที่ตั้งใน $_cacheroot ไว้ด้วย</p>
<p>วิธีเรียกใช้:</p>
<p>สมมติว่า cache คำสั่ง sql นะครับ<br />
ถ้าปกติใช้อย่างนี้</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT * FROM table'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>ก็แก้เป็นประมาณนี้</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT * FROM table'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> cacheget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        cachelock<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$rows</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span>
        cacheset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rows</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/111/php-simple-object-cache/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>0060 &#124; PHP Dynamic page static HTML generator</title>
		<link>http://www.icez.net/blog/102/php-dynamic-page-static-html-generator</link>
		<comments>http://www.icez.net/blog/102/php-dynamic-page-static-html-generator#comments</comments>
		<pubDate>Mon, 25 May 2009 16:59:30 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimize]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=102</guid>
		<description><![CDATA[ชื่อยาวเป็นวา code อะไรวะ (วันหลังมา search จะเจอมั้ยเนี่ยตู 555) code นี้แปะด้านบนสุดของไฟล์ (จะใส่ใน auto prepend เลยก็ยังไหว) &#60;?php $_cachetime = 43200; $_info = parse_url&#40;$_SERVER&#91;&#34;REQUEST_URI&#34;&#93;&#41;; if &#40;!isset&#40;$_info&#91;'query'&#93;&#41;&#41; $_info&#91;'query'&#93; = ''; $_path = end&#40;explode&#40;'/', $_info&#91;'path'&#93;&#41;&#41;; $_info&#91;'query'&#93; = str_replace&#40;'&#38;nocache', '', $_info&#91;'query'&#93;&#41;; $_info&#91;'query'&#93; = str_replace&#40;'nocache&#38;', '', $_info&#91;'query'&#93;&#41;; $_info&#91;'query'&#93; = str_replace&#40;'nocache', '', $_info&#91;'query'&#93;&#41;; $_cachename = sprintf&#40;&#34;%x&#34;, crc32&#40;$_path.&#34;?&#34;.$_info&#91;'query'&#93;&#41;&#41;; $_cachefolder = '/path/to/cache/'.substr&#40;$_cachename,0,2&#41;.'/'; $_cachefile = $_cachefolder.$_cachename; if [...]]]></description>
			<content:encoded><![CDATA[<p>ชื่อยาวเป็นวา code อะไรวะ (วันหลังมา search จะเจอมั้ยเนี่ยตู 555)</p>
<p>code นี้แปะด้านบนสุดของไฟล์ (จะใส่ใน auto prepend เลยก็ยังไหว)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$_cachetime</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">43200</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_path</span> <span style="color: #339933;">=</span> <span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;nocache'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nocache&amp;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nocache'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_cachename</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%x</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">crc32</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_info</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'query'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_cachefolder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/cache/'</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_cachefile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">.</span><span style="color: #000088;">$_cachename</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_URI&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REQUEST_METHOD&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'GET'</span> <span style="color: #339933;">&amp;&amp;</span>
    <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;nocache&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
    <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$_cachetime</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> fetch_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_buffer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$_cachefile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">umask</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefolder</span><span style="color: #339933;">,</span><span style="color: #208080;">0777</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_cachefile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$_buffer</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fetch_cache'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>code นี้ใส่ด้านท้าย (ใน auto append ก็ได้นะครับ)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">ob_end_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>* แก้ไขเพิ่ม 2009/05/28</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/102/php-dynamic-page-static-html-generator/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>0059 &#124; มา scan + กำจัดไวรัส iframe กัน</title>
		<link>http://www.icez.net/blog/72/%e0%b8%a1%e0%b8%b2-scan-%e0%b8%81%e0%b8%b3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b9%84%e0%b8%a7%e0%b8%a3%e0%b8%b1%e0%b8%aa-iframe-%e0%b8%81%e0%b8%b1%e0%b8%99</link>
		<comments>http://www.icez.net/blog/72/%e0%b8%a1%e0%b8%b2-scan-%e0%b8%81%e0%b8%b3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b9%84%e0%b8%a7%e0%b8%a3%e0%b8%b1%e0%b8%aa-iframe-%e0%b8%81%e0%b8%b1%e0%b8%99#comments</comments>
		<pubDate>Wed, 29 Apr 2009 06:15:51 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[virus]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=72</guid>
		<description><![CDATA[ลูกค้าเกิดติดไวรัส ต้องแก้กระทันหัน เลยเขียน script แบบลวกๆ ขึ้นมาตัวนึงครับ *** คำเตือน ก่อนการใช้งานขอให้ระวังว่า&#8230; สั่งพลาดไม่สามารถย้อนได้ ดังนั้น กรุณา backup ข้อมูลก่อนทำนะครับ . เครื่องมือที่ต้องการ: - rpmforge repository [ สำหรับ redhat/centos โหลดได้ที่นี่ ] - clam antivirus [ จะลงจาก rpmforge repository ครับ ] - fixiframe.php (เดี๋ยวมี link ให้โหลดครับ) สำหรับท่านที่ใช้ DA ไม่ต้องห่วงครับ ทดลองแล้วไม่มีปัญหา ไม่ตีกันแน่นอน . หลังจากลง rpmforge repository แล้ว สั่ง yum -y install clamav freshclam wget [...]]]></description>
			<content:encoded><![CDATA[<p>ลูกค้าเกิดติดไวรัส ต้องแก้กระทันหัน เลยเขียน script แบบลวกๆ ขึ้นมาตัวนึงครับ</p>
<p>*** คำเตือน ก่อนการใช้งานขอให้ระวังว่า&#8230; สั่งพลาดไม่สามารถย้อนได้ ดังนั้น กรุณา backup ข้อมูลก่อนทำนะครับ</p>
<p>.</p>
<p>เครื่องมือที่ต้องการ:<br />
- rpmforge repository [ สำหรับ redhat/centos <a href="http://dag.wieers.com/rpm/packages/rpmforge-release/" target="_blank">โหลดได้ที่นี่</a> ]<br />
- clam antivirus [ จะลงจาก rpmforge repository ครับ ]<br />
- fixiframe.php (เดี๋ยวมี link ให้โหลดครับ)</p>
<p>สำหรับท่านที่ใช้ DA ไม่ต้องห่วงครับ ทดลองแล้วไม่มีปัญหา ไม่ตีกันแน่นอน</p>
<p>.</p>
<p>หลังจากลง rpmforge repository แล้ว สั่ง</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> clamav
freshclam
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>clamdb.tar.gz http:<span style="color: #000000; font-weight: bold;">//</span>www.icez.net<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>clamdb.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fixiframe http:<span style="color: #000000; font-weight: bold;">//</span>www.icez.net<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>fixiframe.txt
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;/usr/bin/clamscan -v --stdout -i -d /var/clamav/ -r .|grep FOUND&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>scaniframe
<span style="color: #c20cb9; font-weight: bold;">chmod</span> a+x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fixiframe <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>scaniframe
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>clamav<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxf <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>clamdb.tar.gz
<span style="color: #c20cb9; font-weight: bold;">chown</span> clamav.clamav <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>เตรียมการเรียบร้อยแล้ว ทีนี้&#8230; ก็สั่ง cd เข้าไปในเว็บที่มีปัญหาได้เลยครับ<br />
วิธีใช้งาน&#8230;</p>
<p>หลังจากสั่ง cd เข้าไปที่ folder ที่เก็บเว็บที่มีปัญหา ให้สั่ง scaniframe<br />
พอเจอแฟ้มที่มีปัญหา ลองเปิดแฟ้มดูว่า มี code อะไรแปลกปลอม<br />
แล้วสั่ง fixiframe<br />
มันจะถามว่าต้องการแก้อะไร (ขึ้นว่า SEARCH FOR:) ให้ก๊อป code ที่ต้องการลบ มาวางแล้วกด enter<br />
เจอ+แก้แฟ้มไหนไปบ้างจะรายงานผลขึ้นมาให้เห็นเลยครับ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/72/%e0%b8%a1%e0%b8%b2-scan-%e0%b8%81%e0%b8%b3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b9%84%e0%b8%a7%e0%b8%a3%e0%b8%b1%e0%b8%aa-iframe-%e0%b8%81%e0%b8%b1%e0%b8%99/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>0041 &#124; ตรวจสอบข้อมูลแบบง่ายๆ ด้วย PHP 5.2</title>
		<link>http://www.icez.net/blog/48/%e0%b8%95%e0%b8%a3%e0%b8%a7%e0%b8%88%e0%b8%aa%e0%b8%ad%e0%b8%9a%e0%b8%82%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b8%b9%e0%b8%a5%e0%b9%81%e0%b8%9a%e0%b8%9a%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86</link>
		<comments>http://www.icez.net/blog/48/%e0%b8%95%e0%b8%a3%e0%b8%a7%e0%b8%88%e0%b8%aa%e0%b8%ad%e0%b8%9a%e0%b8%82%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b8%b9%e0%b8%a5%e0%b9%81%e0%b8%9a%e0%b8%9a%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86#comments</comments>
		<pubDate>Sun, 16 Nov 2008 07:19:22 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=48</guid>
		<description><![CDATA[แบบว่านั่งหาข้อมูลไปเรื่อยๆ (จะใช้ทำ project ครับ) ก็เลยเจอไอ้นี่เข้าให้ แจ่มดีแฮะ จะได้ไม่ต้องนั่งจำ regex อยู่ &#60;?php &#160; /*** an IP address ***/ $ip = &#34;2001:0db8:85a3:08d3:1319:8a2e:0370:7334&#34;; &#160; /*** try to validate as IPV6 address ***/ if&#40;filter_var&#40;$ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6&#41; === FALSE&#41; &#123; echo &#34;$ip is not a valid IP&#34;; &#125; else &#123; echo &#34;$ip is valid&#34;; &#125;?&#62; ที่มา: PHP Tutorials Examples Filtering Data [...]]]></description>
			<content:encoded><![CDATA[<p>แบบว่านั่งหาข้อมูลไปเรื่อยๆ<br />
(จะใช้ทำ project ครับ)<br />
ก็เลยเจอไอ้นี่เข้าให้ แจ่มดีแฮะ จะได้ไม่ต้องนั่งจำ regex อยู่</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*** an IP address ***/</span>
<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2001:0db8:85a3:08d3:1319:8a2e:0370:7334&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*** try to validate as IPV6 address ***/</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> FILTER_VALIDATE_IP<span style="color: #339933;">,</span> FILTER_FLAG_IPV6<span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$ip</span> is not a valid IP&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$ip</span> is valid&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>ที่มา:<br />
<a href="http://phpro.org/tutorials/Filtering-Data-with-PHP.html#9" target="_blank">PHP Tutorials Examples Filtering Data with PHP</a><br />
<a href="http://coding.derkeiler.com/Archive/PHP/php.general/2008-07/msg00650.html" target="_blank">[PHP] IPv6 validation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/48/%e0%b8%95%e0%b8%a3%e0%b8%a7%e0%b8%88%e0%b8%aa%e0%b8%ad%e0%b8%9a%e0%b8%82%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b8%b9%e0%b8%a5%e0%b9%81%e0%b8%9a%e0%b8%9a%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>0021 &#124; วิธีนับจำนวนแถว (record) ในตาราง</title>
		<link>http://www.icez.net/blog/25/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b9%81%e0%b8%96%e0%b8%a7-record-%e0%b9%83%e0%b8%99%e0%b8%95%e0%b8%b2%e0%b8%a3%e0%b8%b2</link>
		<comments>http://www.icez.net/blog/25/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b9%81%e0%b8%96%e0%b8%a7-record-%e0%b9%83%e0%b8%99%e0%b8%95%e0%b8%b2%e0%b8%a3%e0%b8%b2#comments</comments>
		<pubDate>Sun, 15 Jun 2008 08:02:57 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[query]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=25</guid>
		<description><![CDATA[ดองไว้นานเชียะ = =&#8217; ขออภัยด้วยครับ แบบว่าขี้เกียจเขียน เอ้ย งานยุ่งๆ มหาลัยเปิดเทอมแล้ว ตารางเรียนเห็นแล้วแทบบ้า เอาวันหยุดของตูคืนมา เอาวันหยุดของตูคืนมา T_T เข้าประเด็นเลยดีกว่า ช่วงนี้มีงานประเภทนี้เยอะครับ เห็นแล้วก็เซ็งไอ้คนเขียนเว็บคนเก่าที่ทำระบบมาจริงๆ คุณพี่เขียนไว้อย่างนี้ครับ&#8230;. $sql = mysql_query&#40;&#34;SELECT * FROM table&#34;&#41;; $records = mysql_num_rows&#40;$sql&#41;; ไอ้อันที่จริงมันก็ไม่ผิดอะไรหรอกครับถ้าจะใช้แบบนี้ เพราะ code มันก็ทำงานได้ปกติสุขดีของมัน แต่&#8230; ใครจะรู้มั้ยครับ ว่า mysql มันต้องส่งข้อมูลมากขนาดไหน สมมติว่า ตารางมีขนาด 1 MB การ query นี้จะทำให้ mysql ต้องส่งข้อมูลขนาด 1 MB ให้ client ที่ทำการ query แล้ว client จะเป็นผู้นับจำนวนแถวเอง ลองคิดดูว่าถ้าตารางเราเกิดมีขนาด 10 MB [...]]]></description>
			<content:encoded><![CDATA[<p>ดองไว้นานเชียะ = =&#8217;<br />
ขออภัยด้วยครับ แบบว่าขี้เกียจเขียน เอ้ย งานยุ่งๆ<br />
มหาลัยเปิดเทอมแล้ว ตารางเรียนเห็นแล้วแทบบ้า<br />
เอาวันหยุดของตูคืนมา เอาวันหยุดของตูคืนมา T_T</p>
<p>เข้าประเด็นเลยดีกว่า</p>
<p>ช่วงนี้มีงานประเภทนี้เยอะครับ เห็นแล้วก็เซ็งไอ้คนเขียนเว็บคนเก่าที่ทำระบบมาจริงๆ<br />
คุณพี่เขียนไว้อย่างนี้ครับ&#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$records</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ไอ้อันที่จริงมันก็ไม่ผิดอะไรหรอกครับถ้าจะใช้แบบนี้ เพราะ code มันก็ทำงานได้ปกติสุขดีของมัน<br />
แต่&#8230; ใครจะรู้มั้ยครับ ว่า mysql มันต้องส่งข้อมูลมากขนาดไหน</p>
<p>สมมติว่า ตารางมีขนาด 1 MB<br />
การ query นี้จะทำให้ mysql ต้องส่งข้อมูลขนาด 1 MB ให้ client ที่ทำการ query<br />
แล้ว client จะเป็นผู้นับจำนวนแถวเอง<br />
ลองคิดดูว่าถ้าตารางเราเกิดมีขนาด 10 MB หรือมีคนเข้าเยอะๆ นะครับ<br />
สมมติ ตารางเดิม ขนาด 1 MB<br />
แต่คนเข้า &#8220;แค่&#8221; นาทีละ 60 ครั้ง (ตกวินาทีละ 1 ครั้ง)<br />
เท่ากับ Database Server ต้องส่งข้อมูลให้ client ถึงวินาทีละ 1 MB<br />
&#8230;<br />
ถ้าขนาดฐานข้อมูลใหญ่ขึ้น<br />
ถ้าคนเข้าเยอะขึ้น&#8230; ลองคิดดูครับว่ามันจะเปลืองทรัพยากรระบบขนาดไหน</p>
<p>วิธีนับจำนวน record จริงๆ ที่ใช้กันทั่วไปในระบบใหญ่ๆ เค้าใช้กันแบบนี้ครับ</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT COUNT(*) FROM table&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$records</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$res</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>จำนวนบรรทัดเยอะขึ้น 1 บรรทัด แต่การทำงานลดลงฮวบฮาบผิดกันลิบๆ</p>
<p>* คำสั่ง SELECT COUNT(*) ห้ามเอาไปใช้กับตารางประเภท InnoDB โดยเด็ดขาดนะครับ<br />
มิเช่นนั้น database server อาจน็อคเอาได้ง่ายๆ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/25/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%99%e0%b8%b1%e0%b8%9a%e0%b8%88%e0%b8%b3%e0%b8%99%e0%b8%a7%e0%b8%99%e0%b9%81%e0%b8%96%e0%b8%a7-record-%e0%b9%83%e0%b8%99%e0%b8%95%e0%b8%b2%e0%b8%a3%e0%b8%b2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>0015 &#124; PHP Email Validation</title>
		<link>http://www.icez.net/blog/19/php-email-validation</link>
		<comments>http://www.icez.net/blog/19/php-email-validation#comments</comments>
		<pubDate>Wed, 14 May 2008 09:48:28 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=19</guid>
		<description><![CDATA[บทความนี้อ้างอิง + คัดลอกมาจากเว็บไซต์ต่อไปนี้ Spoono.com &#8211; Spoono &#8211; PHP Tutorials &#8211; Email Validation แบบว่ากำลังหาตัว validate email เพลินๆ ไปเจอตัวนี้มา ถูกใจครับ (ฮาๆ) เอามาลง เผื่อเก็บไว้ใช้อีก function checkEmail($email) { if (eregi(&#8220;^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]&#8221;, $email)) { return false; } list($Username, $Domain) = split(&#8220;@&#8221;,$email); if (getmxrr($Domain, $MXHost)) { return true; } else { if (fsockopen($Domain, 25, $errno, $errstr, 7)) { return true; } else [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้อ้างอิง + คัดลอกมาจากเว็บไซต์ต่อไปนี้<br />
Spoono.com &#8211; <a href="http://www.spoono.com/php/tutorials/tutorial.php?id=41" target="_blank">Spoono &#8211; PHP Tutorials &#8211; Email Validation</a></p>
<p>แบบว่ากำลังหาตัว validate email เพลินๆ ไปเจอตัวนี้มา ถูกใจครับ (ฮาๆ)<br />
เอามาลง เผื่อเก็บไว้ใช้อีก</p>
<blockquote><p><span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">function </span><span style="color: #<a href="http://search.twitter.com/search?q=%23993300" rel="nofollow" target="_blank" title="Search Twitter for &quot;993300&quot;">993300</a>;">checkEmail</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$email</span>) {<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">if</span> (<span style="color: #<a href="http://search.twitter.com/search?q=%23ff0000" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff0000&quot;">ff0000</a>;">eregi</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23ff00ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff00ff&quot;">ff00ff</a>;">&#8220;^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]&#8221;</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$email</span>)) {<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">return false</span>;<br />
}</p>
<p><span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">list</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$Username</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$Domain</span>) = <span style="color: #<a href="http://search.twitter.com/search?q=%23ff0000" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff0000&quot;">ff0000</a>;">split</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23ff00ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff00ff&quot;">ff00ff</a>;">&#8220;@&#8221;</span>,<span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$email</span>);</p>
<p><span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">if </span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23ff0000" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff0000&quot;">ff0000</a>;">getmxrr</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$Domain</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$MXHost</span>)) {<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">return true;</span><br />
} <span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">else </span>{<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">if </span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23ff0000" rel="nofollow" target="_blank" title="Search Twitter for &quot;ff0000&quot;">ff0000</a>;">fsockopen</span>(<span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$Domain</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23993300" rel="nofollow" target="_blank" title="Search Twitter for &quot;993300&quot;">993300</a>;">25</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$errno</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23008080" rel="nofollow" target="_blank" title="Search Twitter for &quot;008080&quot;">008080</a>;">$errstr</span>, <span style="color: #<a href="http://search.twitter.com/search?q=%23993300" rel="nofollow" target="_blank" title="Search Twitter for &quot;993300&quot;">993300</a>;">7</span>)) {<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">return true</span>;<br />
} <span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">else </span>{<br />
<span style="color: #<a href="http://search.twitter.com/search?q=%230000ff" rel="nofollow" target="_blank" title="Search Twitter for &quot;0000ff&quot;">0000ff</a>;">return false</span>;<br />
}<br />
}<br />
}</p></blockquote>
<p>ปล. ทำ syntax highlight แบบอัตโนมือนี่เหนื่อยนะเนี่ย</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/19/php-email-validation/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>0007 &#124; gzip compression กับการใช้งาน CPU</title>
		<link>http://www.icez.net/blog/10/gzip-compression-%e0%b8%81%e0%b8%b1%e0%b8%9a%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-cpu</link>
		<comments>http://www.icez.net/blog/10/gzip-compression-%e0%b8%81%e0%b8%b1%e0%b8%9a%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-cpu#comments</comments>
		<pubDate>Sat, 03 May 2008 17:39:13 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[IP Network]]></category>
		<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[optimize]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=10</guid>
		<description><![CDATA[จาก entry ที่ 4 (รับมือเว็บ 250 req/sec) บัดนี้ผลการทดลองออกมาแล้วครับ กราฟบน เป็นปริมาณ traffic ส่วนกราฟล่าง เป็นปริมาณการใช้งาน CPU ครับ ด้านการใช้งาน CPU สรุปได้สั้นๆ ง่ายๆ ว่า ไม่ต่าง&#8230; แล้วตูจะปิด gzip ไปทำไมเนี่ย ในเมื่อกราฟบนมันบอกว่า ปิด gzip ไปแล้ว เปลือง bandwidth ขึ้นตั้งสองเท่าแน่ะ สังเกตตรงที่ลูกศรชี้นะครับ ตรงนั้นคือผมสั่งเปิดการทำงานของ gzip compression อีกรอบ แล้วก็ลงมาดูกราฟ CPU ที่ตำแหน่งเดียวกัน ไม่เห็นมันจะเปลือง CPU มากขึ้นเลยซักนิด ว่าแต่งานนี้คงต้อง compile PHP ใหม่ละมั้งนี่ เห้อ&#8230;]]></description>
			<content:encoded><![CDATA[<p>จาก entry ที่ 4 <a title="รับมือเว็บ 250 req/sec" href="http://www.icez.net/blog/6/%e0%b8%a3%e0%b8%b1%e0%b8%9a%e0%b8%a1%e0%b8%b7%e0%b8%ad%e0%b9%80%e0%b8%a7%e0%b9%87%e0%b8%9a-250-reqsec" target="_blank">(รับมือเว็บ 250 req/sec</a>) บัดนี้ผลการทดลองออกมาแล้วครับ</p>
<p><img src="http://img.thzhost.com/i/5u/aoisc.png" alt="" width="525" height="346" /></p>
<p>กราฟบน เป็นปริมาณ traffic<br />
ส่วนกราฟล่าง เป็นปริมาณการใช้งาน CPU ครับ</p>
<p>ด้านการใช้งาน CPU สรุปได้สั้นๆ ง่ายๆ ว่า ไม่ต่าง&#8230;<br />
แล้วตูจะปิด gzip ไปทำไมเนี่ย ในเมื่อกราฟบนมันบอกว่า<br />
ปิด gzip ไปแล้ว เปลือง bandwidth ขึ้นตั้งสองเท่าแน่ะ</p>
<p>สังเกตตรงที่ลูกศรชี้นะครับ ตรงนั้นคือผมสั่งเปิดการทำงานของ gzip compression อีกรอบ<br />
แล้วก็ลงมาดูกราฟ CPU ที่ตำแหน่งเดียวกัน ไม่เห็นมันจะเปลือง CPU มากขึ้นเลยซักนิด</p>
<p>ว่าแต่งานนี้คงต้อง compile PHP ใหม่ละมั้งนี่ เห้อ&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/10/gzip-compression-%e0%b8%81%e0%b8%b1%e0%b8%9a%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-cpu/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>0004 &#124; PHP Memory Limit</title>
		<link>http://www.icez.net/blog/7/php-memory-limit</link>
		<comments>http://www.icez.net/blog/7/php-memory-limit#comments</comments>
		<pubDate>Sat, 03 May 2008 09:51:38 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[PHP Coding]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[optimize]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=7</guid>
		<description><![CDATA[Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 4864 bytes) in /path/to/script.php on line 1074 ข้อผิดพลาดนี้ (อันที่จริงก็ทุกอัน) คนทำเว็บคนไหนก็คงไม่ชอบให้มันขึ้นมาหรอกจริงมั้ยครับ วันนี้จะมาอธิบายการทำงานของ memory limit นิดนึง&#8230; การที่ error อันนี้ขึ้นมาเนี่ย มันกำลังพยายามบอกว่า ก่อนหน้านี้ มีการขอใช้หน่วยความจำไปแล้วจนเกือบเต็ม 262144 byte (คือเหลือหน่วยความจำว่างๆ อีกไม่เยอะ) แล้วมีการขอใช้เพิ่มอีก 4864 byte แต่พื้นที่หน่วยความจำที่เหลืออยู่ (ตามที่อนุญาตไว้) มีไม่พอให้ใช้ มันก็เลยต้องจบการทำงานลง เพราะหน่วยความจำหมด นี่แหละครับคือหน้าที่ของ memory limit ตัว memory limit มีไว้สำหรับจำกัดการใช้งานหน่วยความจำ ของ &#8220;ตัวแปร&#8221; ใน PHP [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Fatal error</strong>: Allowed memory size of 262144 bytes exhausted (tried to allocate 4864 bytes) in /path/to/script.php on line 1074</p>
<p>ข้อผิดพลาดนี้ (อันที่จริงก็ทุกอัน) คนทำเว็บคนไหนก็คงไม่ชอบให้มันขึ้นมาหรอกจริงมั้ยครับ<br />
วันนี้จะมาอธิบายการทำงานของ memory limit นิดนึง&#8230;</p>
<p>การที่ error อันนี้ขึ้นมาเนี่ย มันกำลังพยายามบอกว่า<br />
ก่อนหน้านี้ มีการขอใช้หน่วยความจำไปแล้วจนเกือบเต็ม 262144 byte (คือเหลือหน่วยความจำว่างๆ อีกไม่เยอะ)<br />
แล้วมีการขอใช้เพิ่มอีก 4864 byte แต่พื้นที่หน่วยความจำที่เหลืออยู่ (ตามที่อนุญาตไว้) มีไม่พอให้ใช้<br />
มันก็เลยต้องจบการทำงานลง เพราะหน่วยความจำหมด</p>
<p>นี่แหละครับคือหน้าที่ของ memory limit</p>
<p>ตัว memory limit มีไว้สำหรับจำกัดการใช้งานหน่วยความจำ ของ &#8220;<strong>ตัวแปร</strong>&#8221; ใน PHP ครับ<br />
แบ่งเป็นตัวแปรจากระบบ (พวก $_SERVER $_GET $_POST $_ENV $_SESSION $_COOKIE)<br />
พวกนี้กินอย่างมากก็ประมาณ 50 KB ครับ แล้วที่เหลือก็เป็นส่วนของการทำงานใน code ไป</p>
<p>เชื่อมั้ยครับว่าค่าที่เหมาะสมสำหรับเว็บทั่วไปอยู่ที่ <strong>&#8220;2M&#8221;</strong> เอง เพราะปกติเราก็ไม่ใช้อะไรเยอะแยะอยู่แล้ว<br />
สำหรับเว็บที่มีการเรียกใช้ gd library (พวกที่มี captcha อะไรพวกนี้ด้วย) ควรปรับประมาณ 16-24 M<br />
แล้วก็ เว็บฝากไฟล์&#8230;. ใช้เท่ากะเว็บปกติครับ (สำหรับส่วนของการ upload)<br />
เนื่องจาก content ในไฟล์ ไม่ได้ถูกนำมาเก็บในหน่วยความจำครับ<br />
ส่วนพวก CMS ต่างๆ เช่น joomla / mambo / phpnuke / wordpress / drupal พวกนี้ควรตั้งขั้นต่ำที่ 8M ครับ<br />
แล้วก็พวก webboard เช่น SMF / IPB / vBullentin / phpBB ควรตั้งขั้นต่ำ 16M ครับ</p>
<p>แต่เอาเข้าจริง ถ้าใช้ไม่ถึงมันก็กินไม่เยอะ ค่าพวกนี้เป็นเพียงแค่การตั้งค่าสูงสุดที่อนุญาตเท่านั้นครับ<br />
ส่วนสำคัญอยู่ที่การ optimize code ของเราให้ทำงานได้เร็ว และประหยัดหน่วยความจำได้มากที่สุดมากกว่า<br />
แล้วถามว่า จะจำกัดไปทำไม ? แรมเหลือเฟือซะอย่าง ไม่กลัวอยู่แล้ว<br />
ลองคิดดูนะครับ สมมติโปรแกรมเมอร์ต้องการลองของ เขียน code นี้ขึ้นมา</p>
<p>$test = &#8220;&#8221;;<br />
<span style="color: red;">while (1)</span> {<br />
$test .= &#8220;more&#8221;;<br />
}</p>
<p>ถ้าเกิดไม่มี memory limit นี่เครื่องพังแน่นอนครับ (ใช้แรมเกิน)<br />
แต่กรณีปกติที่อาจจะเกิด คือเขียน script วนซ้ำ แล้ว<span style="text-decoration: underline;">เงื่อนไขการวนซ้ำผิดพลาด<br />
</span>ทำให้เกิดการวนซ้ำไม่รู้จบ (infinite loop) จนมีการจองหน่วยความจำเพิ่มขึ้นเรื่อยๆ<br />
แล้วสุดท้าย หน่วยความจำล้น (buffer overflow) เป็นเหตุให้โดน hack หรืออะไรต่างๆ ตามมาได้มากครับ</p>
<p>วิธีการตรวจสอบหน่วยความจำที่ใช้ไปแล้ว<br />
ใน PHP จะมี function ตัวนึงครับ ไว้เรียกใช้เพื่อดูว่า<br />
ตั้งแต่บรรทัดแรก จนถึง code บรรทัดที่เรียกคำสั่งนี้ ใช้ memory ไปแล้วเท่าไหร่</p>
<p><a href="http://th.php.net/manual/en/function.memory-get-usage.php" target="_blank">http://th.php.net/manual/en/function.memory-get-usage.php</a></p>
<p>ดูใน docs นะครับ ใช้ไม่ยากๆ</p>
<p>ปล. entry นี้อ้างอิงจากที่ &gt; <a href="http://www.thaiseoboard.com/index.php/topic,27668.msg353257.html#msg353257">ThaiSEOBoard # ความงี่เง่าของ SLHost</a> &lt;</p>
<p>ปปล. entry นี้เขียน ปล. ก่อนเนื้อหาซะอีก</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/7/php-memory-limit/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.icez.net @ 2012-02-10 17:26:40 -->
