<?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>MEMOBALL.info &#187; Programming</title>
	<atom:link href="http://www.memoball.info/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.memoball.info</link>
	<description>All of my Memories</description>
	<lastBuildDate>Thu, 22 Jul 2010 06:17:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Memcache &amp; MySQL PHP Session Handler</title>
		<link>http://www.memoball.info/03/memcache-mysql-php-session-handler/</link>
		<comments>http://www.memoball.info/03/memcache-mysql-php-session-handler/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 04:19:56 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=457</guid>
		<description><![CDATA[ช่วงนี้กำลังหาโซลูชั้นเพื่อที่จะทำ centralized session ตรงกลาง เพราะเนื่องจากเริ่มมี web application หลายตัว และในบางส่วนจำเป็นต้องมีการใช้ session ร่วมกัน จึงหาการแก้ปัญหาที่ตอบโจทย์ดังกล่าวว่าจะมีการรวม session มาไว้ที่เดียวกันและมีประสิทธิภาพสูงสุดได้อย่างไร ซึ่งในโซลูชั่นสุดท้ายผมคงต้องขอไม่พูดถึง เพี่อเป็นความปลอดภัยของระบบ แต่จะกล่าวแค่เฉพาะแนวคิดเฉยๆ ครับ

การทำ centralized session หรือ เซสชั่นกลางนั้น เราสามารถทำได้ง่ายๆ โดยการหาตัวมารับหน้าที่เป็น data pool หรือที่เก็บรวบรวมข้อมูลตรงกลาง ซึ่งที่ผมจะนำไปใช้คือ MySQL สำหรับ บรรจุข้อมูลตรงกลาง ทุกเครื่องสามารถนำไปใช้งานได้ โดยเป็นข้อมูลเดียวกัน แต่เนื่องจาก MySQL จะทำการ update cache ทุกครั้งที่กำการอัพเดตข้อมูล
http://pureform.wordpress.com/2009/04/08/memcache-mysql-php-session-handler/
This is protected content. Please Login or Register for access.ช่วงนี้กำลังหาโซลูชั้นเพื่อที่จะทำ centralized session ตรงกลาง เพราะเนื่องจากเริ่มมี web application หลายตัว [...]]]></description>
			<content:encoded><![CDATA[<p>ช่วงนี้กำลังหาโซลูชั้นเพื่อที่จะทำ centralized session ตรงกลาง เพราะเนื่องจากเริ่มมี web application หลายตัว และในบางส่วนจำเป็นต้องมีการใช้ session ร่วมกัน จึงหาการแก้ปัญหาที่ตอบโจทย์ดังกล่าวว่าจะมีการรวม session มาไว้ที่เดียวกันและมีประสิทธิภาพสูงสุดได้อย่างไร ซึ่งในโซลูชั่นสุดท้ายผมคงต้องขอไม่พูดถึง เพี่อเป็นความปลอดภัยของระบบ แต่จะกล่าวแค่เฉพาะแนวคิดเฉยๆ ครับ<br />
<span id="more-457"></span><br />
การทำ centralized session หรือ เซสชั่นกลางนั้น เราสามารถทำได้ง่ายๆ โดยการหาตัวมารับหน้าที่เป็น data pool หรือที่เก็บรวบรวมข้อมูลตรงกลาง ซึ่งที่ผมจะนำไปใช้คือ MySQL สำหรับ บรรจุข้อมูลตรงกลาง ทุกเครื่องสามารถนำไปใช้งานได้ โดยเป็นข้อมูลเดียวกัน แต่เนื่องจาก MySQL จะทำการ update cache ทุกครั้งที่กำการอัพเดตข้อมูล</p>
<p><a href="http://pureform.wordpress.com/2009/04/08/memcache-mysql-php-session-handler/">http://pureform.wordpress.com/2009/04/08/memcache-mysql-php-session-handler/</a><br />
<br/><div id="wp-private-box"><b>This is protected content. Please <a href="http://www.memoball.info/wp-login.php">Login</a> or <a href="http://www.memoball.info/wp-register.php">Register</a> for access.</b></div><br/><p>ช่วงนี้กำลังหาโซลูชั้นเพื่อที่จะทำ centralized session ตรงกลาง เพราะเนื่องจากเริ่มมี web application หลายตัว และในบางส่วนจำเป็นต้องมีการใช้ session ร่วมกัน จึงหาการแก้ปัญหาที่ตอบโจทย์ดังกล่าวว่าจะมีการรวม session มาไว้ที่เดียวกันและมีประสิทธิภาพสูงสุดได้อย่างไร ซึ่งในโซลูชั่นสุดท้ายผมคงต้องขอไม่พูดถึง เพี่อเป็นความปลอดภัยของระบบ แต่จะกล่าวแค่เฉพาะแนวคิดเฉยๆ ครับ<br />
<span id="more-457"></span><br />
การทำ centralized session หรือ เซสชั่นกลางนั้น เราสามารถทำได้ง่ายๆ โดยการหาตัวมารับหน้าที่เป็น data pool หรือที่เก็บรวบรวมข้อมูลตรงกลาง ซึ่งที่ผมจะนำไปใช้คือ MySQL สำหรับ บรรจุข้อมูลตรงกลาง ทุกเครื่องสามารถนำไปใช้งานได้ โดยเป็นข้อมูลเดียวกัน แต่เนื่องจาก MySQL จะทำการ update cache ทุกครั้งที่กำการอัพเดตข้อมูล</p>
<p><a href="http://pureform.wordpress.com/2009/04/08/memcache-mysql-php-session-handler/">http://pureform.wordpress.com/2009/04/08/memcache-mysql-php-session-handler/</a><br />
<!--protected--></p>
<pre>
memcache = new Memcache;
            $this-&gt;lifeTime = intval(ini_get("session.gc_maxlifetime"));
            $this-&gt;initSessionData = null;
            $this-&gt;memcache-&gt;connect("127.0.0.1",11211);

            return true;
        }

        function open($savePath,$sessionName) {
            $sessionID = session_id();
            if ($sessionID !== "") {
                $this-&gt;initSessionData = $this-&gt;read($sessionID);
            }

            return true;
        }

        function close() {
            $this-&gt;lifeTime = null;
            $this-&gt;memcache = null;
            $this-&gt;initSessionData = null;

            return true;
        }

        function read($sessionID) {
            $data = $this-&gt;memcache-&gt;get($sessionID);
            if ($data === false) {
                # Couldn't find it in MC, ask the DB for it

                $sessionIDEscaped = mysql_real_escape_string($sessionID);
                $r = mysql_query("SELECT `sessionData` FROM `tblsessions` WHERE `sessionID`='$sessionIDEscaped'");
                if (is_resource($r) &amp;&amp; (mysql_num_rows($r) !== 0)) {
                    $data = mysql_result($r,0,"sessionData");
                }

                # Refresh MC key: [Thanks Cal <img src='http://www.memoball.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ]
                $this-&gt;memcache-&gt;set($sessionID,$data,false,$this-&gt;lifeTime);
            }

            # The default miss for MC is (bool) false, so return it
            return $data;
        }

        function write($sessionID,$data) {
            # This is called upon script termination or when session_write_close() is called, which ever is first.
            $result = $this-&gt;memcache-&gt;set($sessionID,$data,false,$this-&gt;lifeTime);

            if ($this-&gt;initSessionData !== $data) {
                $sessionID = mysql_real_escape_string($sessionID);
                $sessionExpirationTS = ($this-&gt;lifeTime + time());
                $sessionData = mysql_real_escape_string($data);

                $r = mysql_query("REPLACE INTO `tblsessions` (`sessionID`,`sessionExpirationTS`,`sessionData`) VALUES('$sessionID',$sessionExpirationTS,'$sessionData')");
                $result = is_resource($r);
            }

            return $result;
        }

        function destroy($sessionID) {
            # Called when a user logs out...
            $this-&gt;memcache-&gt;delete($sessionID);
            $sessionID = mysql_real_escape_string($sessionID);
            mysql_query("DELETE FROM `tblsessions` WHERE `sessionID`='$sessionID'");

            return true;
        }

        function gc($maxlifetime) {
            # We need this atomic so it can clear MC keys as well...
            $r = mysql_query("SELECT `sessionID` FROM `tblsessions` WHERE `sessionExpirationTS`lifeTime));
            if (is_resource($r) &amp;&amp; (($rows = mysql_num_rows($r)) !== 0)) {
                for ($i=0;$idestroy(mysql_result($r,$i,"sessionID"));
                }
            }

            return true;
        }
    }

    ini_set("session.gc_maxlifetime",60 * 30); # 30 minutes
    session_set_cookie_params(0,"/",".myapp.com",false,true);
    session_name("MYAPPSESSION");
    $sessionHandler = new SessionHandler();
    session_set_save_handler(array (&amp;$sessionHandler,"open"),array (&amp;$sessionHandler,"close"),array (&amp;$sessionHandler,"read"),array (&amp;$sessionHandler,"write"),array (&amp;$sessionHandler,"destroy"),array (&amp;$sessionHandler,"gc"));
    session_start();
?&gt;
</pre>
<p><!--protected--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/03/memcache-mysql-php-session-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>70 web application ที่น่าสนใจ</title>
		<link>http://www.memoball.info/02/70-web-application-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b8%99%e0%b9%88%e0%b8%b2%e0%b8%aa%e0%b8%99%e0%b9%83%e0%b8%88/</link>
		<comments>http://www.memoball.info/02/70-web-application-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b8%99%e0%b9%88%e0%b8%b2%e0%b8%aa%e0%b8%99%e0%b9%83%e0%b8%88/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 02:12:03 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=447</guid>
		<description><![CDATA[This is protected content. Please Login or Register for access.
]]></description>
			<content:encoded><![CDATA[<br/><div id="wp-private-box"><b>This is protected content. Please <a href="http://www.memoball.info/wp-login.php">Login</a> or <a href="http://www.memoball.info/wp-register.php">Register</a> for access.</b></div><br/><!--/protected--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/70-web-application-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b8%99%e0%b9%88%e0%b8%b2%e0%b8%aa%e0%b8%99%e0%b9%83%e0%b8%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java-script ใน css</title>
		<link>http://www.memoball.info/02/java-script-%e0%b9%83%e0%b8%99-css/</link>
		<comments>http://www.memoball.info/02/java-script-%e0%b9%83%e0%b8%99-css/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 12:40:58 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=442</guid>
		<description><![CDATA[ท่านสามารถใส java-script ไว้สำหรับทำการแก้ bug ของ ie6 ซึ่งไม่สามารถแสดงผลได้อย่างถูกต้อง โดยการใส่ expression ดังตั่วอย่าง

#container{
	width: expression(document.body.clientWidth &#62; 1100)? "1100px" : "auto";
	/* For web browsers supporting it */
	max-width: 1100px;
}

]]></description>
			<content:encoded><![CDATA[<p>ท่านสามารถใส java-script ไว้สำหรับทำการแก้ bug ของ ie6 ซึ่งไม่สามารถแสดงผลได้อย่างถูกต้อง โดยการใส่ expression ดังตั่วอย่าง</p>
<pre>
#container{
	width: expression(document.body.clientWidth &gt; 1100)? "1100px" : "auto";
	/* For web browsers supporting it */
	max-width: 1100px;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/java-script-%e0%b9%83%e0%b8%99-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>วาดภาพบน HTML5</title>
		<link>http://www.memoball.info/02/%e0%b8%a7%e0%b8%b2%e0%b8%94%e0%b8%a0%e0%b8%b2%e0%b8%9e%e0%b8%9a%e0%b8%99-html5/</link>
		<comments>http://www.memoball.info/02/%e0%b8%a7%e0%b8%b2%e0%b8%94%e0%b8%a0%e0%b8%b2%e0%b8%9e%e0%b8%9a%e0%b8%99-html5/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 00:09:25 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=436</guid>
		<description><![CDATA[ถ้าคุณอยากมีโปรแกรมวาดภาพซักตัวบนเวป โดยที่คุณไม่ต้องใช้ flash คุณสามารถลองใช้ http://mugtug.com/sketchpad/ ตัวนี้ได้เลยครับ
]]></description>
			<content:encoded><![CDATA[<p>ถ้าคุณอยากมีโปรแกรมวาดภาพซักตัวบนเวป โดยที่คุณไม่ต้องใช้ flash คุณสามารถลองใช้<a href="http://mugtug.com/sketchpad/"> http://mugtug.com/sketchpad/</a> ตัวนี้ได้เลยครับ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/%e0%b8%a7%e0%b8%b2%e0%b8%94%e0%b8%a0%e0%b8%b2%e0%b8%9e%e0%b8%9a%e0%b8%99-html5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>รูปในเวปผมหายไปไหน</title>
		<link>http://www.memoball.info/02/%e0%b8%a3%e0%b8%b9%e0%b8%9b%e0%b9%83%e0%b8%99%e0%b9%80%e0%b8%a7%e0%b8%9b%e0%b8%9c%e0%b8%a1%e0%b8%ab%e0%b8%b2%e0%b8%a2%e0%b9%84%e0%b8%9b%e0%b9%84%e0%b8%ab%e0%b8%99/</link>
		<comments>http://www.memoball.info/02/%e0%b8%a3%e0%b8%b9%e0%b8%9b%e0%b9%83%e0%b8%99%e0%b9%80%e0%b8%a7%e0%b8%9b%e0%b8%9c%e0%b8%a1%e0%b8%ab%e0%b8%b2%e0%b8%a2%e0%b9%84%e0%b8%9b%e0%b9%84%e0%b8%ab%e0%b8%99/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 00:33:59 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=432</guid>
		<description><![CDATA[เมื่อหลายวันก่อนผมทำการแก้ไขเวปเซอร์วิช ซึ่งเป็น web-apllication ตัวหนึ่งที่ผมดูและอยู่ ปรากฏว่ารูปที่เป็นส่วนประกอบของผมหายไปอย่างลึกลับเมื่อผู้ใช้งานทั่วไปเข้าไปใช้ ซึ่งในเบื้องต้น ผมใช้ ubuntu+firefox ไม่เกิดข้อผิดพลาดใดๆ ในกรณีดังกล่าว จะเป็นเฉพาะ HTTP over SSL (HTTPS) 
สาเหตุ
สาเหตุก็เป็นเพราะว่า รูปผมมันเป็น http แต่เวปมันเป็น https บราวเซอร์จะไม่ยอมโหลดรูปให้ ปัญหาดังกล่าวจะเป็นเกือบทุกบราวเซอร์ โดยบางเครื่องอาจมีการถามก่อนว่าจะโหลดหรือไม่ ตามแต่ผู้ใช้งานจะเป็นผู้ตั้งไว้ แต่จุดที่สังเกตได้ง่ายๆ คือด้านมุมขวาล่าง จะมีรูปแม่กุญแจอยู่ ถ้าเป็นกรณีนี่มีการโหลด http บนเวป https จะมีรูปเครื่องหมายตกใจสีแดงปรากฎอยู่บนรูปแม่กุญแจนั้น
วิธีแก้ไข
วิธีแก้ไขที่ดีที่สุดน่าจะอยู่ที่ตัวผู้เขียนเวปเอง โดยทำการกำหนด link ต่างๆ ในหน้าเวปของเราให้เป็น https ซะ
]]></description>
			<content:encoded><![CDATA[<p>เมื่อหลายวันก่อนผมทำการแก้ไขเวปเซอร์วิช ซึ่งเป็น web-apllication ตัวหนึ่งที่ผมดูและอยู่ ปรากฏว่ารูปที่เป็นส่วนประกอบของผมหายไปอย่างลึกลับเมื่อผู้ใช้งานทั่วไปเข้าไปใช้ ซึ่งในเบื้องต้น ผมใช้ ubuntu+firefox ไม่เกิดข้อผิดพลาดใดๆ ในกรณีดังกล่าว จะเป็นเฉพาะ HTTP over SSL (HTTPS) <span id="more-432"></span></p>
<h2>สาเหตุ</h2>
<p>สาเหตุก็เป็นเพราะว่า รูปผมมันเป็น http แต่เวปมันเป็น https บราวเซอร์จะไม่ยอมโหลดรูปให้ ปัญหาดังกล่าวจะเป็นเกือบทุกบราวเซอร์ โดยบางเครื่องอาจมีการถามก่อนว่าจะโหลดหรือไม่ ตามแต่ผู้ใช้งานจะเป็นผู้ตั้งไว้ แต่จุดที่สังเกตได้ง่ายๆ คือด้านมุมขวาล่าง จะมีรูปแม่กุญแจอยู่ ถ้าเป็นกรณีนี่มีการโหลด http บนเวป https จะมีรูปเครื่องหมายตกใจสีแดงปรากฎอยู่บนรูปแม่กุญแจนั้น</p>
<h2>วิธีแก้ไข</h2>
<p>วิธีแก้ไขที่ดีที่สุดน่าจะอยู่ที่ตัวผู้เขียนเวปเอง โดยทำการกำหนด link ต่างๆ ในหน้าเวปของเราให้เป็น https ซะ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/%e0%b8%a3%e0%b8%b9%e0%b8%9b%e0%b9%83%e0%b8%99%e0%b9%80%e0%b8%a7%e0%b8%9b%e0%b8%9c%e0%b8%a1%e0%b8%ab%e0%b8%b2%e0%b8%a2%e0%b9%84%e0%b8%9b%e0%b9%84%e0%b8%ab%e0%b8%99/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Download file over SSL Error with Internet Explorer</title>
		<link>http://www.memoball.info/02/download-file-over-ssl-error-with-internet-explorer/</link>
		<comments>http://www.memoball.info/02/download-file-over-ssl-error-with-internet-explorer/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 00:20:14 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[web bug]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=427</guid>
		<description><![CDATA[เมื่ออาทิตย์ก่อน ผมเจอปัญหาที่ทำอยู่ที่ทำงานครับ ซึ่งงานผมเป็น service ที่ทำงานอยู่บน SSL หรือพูดให้ฟังดูง่ายๆ คือ https นั้นเอง ปัญหาที่ผมกับผู้ใช้งานเซอร์วิชก็คือ ไม่สามารถดาวโหลดแฟ้มข้อมูลได้
ปัญหา
ไม่สามารถโหลดไฟล์ผ่าน SSL  โดยปัญหานี้พบกับเฉพาะ Internet Explorer 7 (IE7 โดย IE รุ่นอื่น ยังไม่ได้รับรายงานปัญหาดังกล่าว) ส่วนบราวเซอร์ตัวอื่นยังไม่พบปัญหาเช่นนี้ โดย error ที่พบ IE จะขึ้นมาที่ผู้ใช้ว่า &#8220;the file could not be written to the cache&#8221; ทำให้ไม่สามารถดาวโหลดไฟล์ได้
วิธีการแก้ไข
สามารถเลือกแก้ไขได้โดยวิธีใดวิธีหนึ่งดังนี้
สำหรับ server admin หรือ webmaster
ห้ามใส่ cache-control หรือ pragma: no-cache ลงใน header ของ http ในส่วนที่เป็น oct-stream หรือ file-download
สำหรับ client [...]]]></description>
			<content:encoded><![CDATA[<p>เมื่ออาทิตย์ก่อน ผมเจอปัญหาที่ทำอยู่ที่ทำงานครับ ซึ่งงานผมเป็น service ที่ทำงานอยู่บน SSL หรือพูดให้ฟังดูง่ายๆ คือ https นั้นเอง ปัญหาที่ผมกับผู้ใช้งานเซอร์วิชก็คือ ไม่สามารถดาวโหลดแฟ้มข้อมูลได้<span id="more-427"></span></p>
<h2>ปัญหา</h2>
<p>ไม่สามารถโหลดไฟล์ผ่าน SSL  โดยปัญหานี้พบกับเฉพาะ Internet Explorer 7 (IE7 โดย IE รุ่นอื่น ยังไม่ได้รับรายงานปัญหาดังกล่าว) ส่วนบราวเซอร์ตัวอื่นยังไม่พบปัญหาเช่นนี้ โดย error ที่พบ IE จะขึ้นมาที่ผู้ใช้ว่า <strong>&#8220;the file could not be written to the cache&#8221; </strong>ทำให้ไม่สามารถดาวโหลดไฟล์ได้</p>
<h2>วิธีการแก้ไข</h2>
<p>สามารถเลือกแก้ไขได้โดยวิธีใดวิธีหนึ่งดังนี้</p>
<h3>สำหรับ server admin หรือ webmaster</h3>
<p>ห้ามใส่ cache-control หรือ pragma: no-cache ลงใน header ของ http ในส่วนที่เป็น oct-stream หรือ file-download</p>
<h3>สำหรับ client (ผมยังไม่ได้ลองครับ)</h3>
<p>เข้าไป uncheck ตามลำดับดังนี้ IE Tools -&gt; Internet Options -&gt; Advanced -&gt; Security -&gt;<strong> Do not save encrypted<br />
pages to disk </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/download-file-over-ssl-error-with-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การเขียน makefile</title>
		<link>http://www.memoball.info/01/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-makefile/</link>
		<comments>http://www.memoball.info/01/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-makefile/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 03:56:53 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=420</guid>
		<description><![CDATA[วันนี้ได้ทำการเขียน makefile ใหม่ให้มีประสิทธิ์ภาพมากขึ้น โดยการใช้ inference rules จึงไปค้นหาเวปมาได้เวปดีๆ คือ
http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html 


Getting started with Makefiles: Advanced features

1. What are macros and why should I use them?
Think of programs that shall be used at different locations: CERN, DESY, SLAC, University of Bonn, &#8230; The C/C++ programs are highly portable (at least after some effort) but the names of the [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ได้ทำการเขียน makefile ใหม่ให้มีประสิทธิ์ภาพมากขึ้น โดยการใช้ inference rules จึงไปค้นหาเวปมาได้เวปดีๆ คือ<br />
<a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html">http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html</a> <span id="more-420"></span></p>
<h2>
<hr noshade="noshade" /></h2>
<h2><span style="font-family: Arial,Helvetica">Getting started with Makefiles: Advanced features</span></h2>
<hr noshade="noshade" />
<h2><span style="font-family: Arial,Helvetica">1. What are macros and why should I use them?</span></h2>
<p>Think of programs that shall be used at different locations: CERN, DESY, SLAC, University of Bonn, &#8230; The C/C++ programs are highly portable (at least after some effort) but the names of the programs used to compile them &#8211; as well as their arguments &#8211; may be very different. So it would be nice to once give the program name, the list of arguments, etc. and then only use symbolic names so that you can rapidly adjust to the local computing environment. Those symbolic names are called &#8220;macros&#8221;. Let&#8217;s recall<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile5">Makefile5</a></strong>.</tt></p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.IGNORE:</tt></strong><br />
<strong><tt>.SILENT:</tt></strong><strong><tt>mirror:    input.o mirror.o process.o output.o</tt></strong><br />
<strong><tt> g++ -o mirror input.o mirror.o process.o output.o</tt></strong></p>
<p><strong><tt>mirror.o:  mirror.cc</tt></strong><br />
<strong><tt> g++ -c -Wall mirror.cc</tt></strong></p>
<p><strong><tt>input.o:   input.cc</tt></strong><br />
<strong><tt> g++ -c -Wall input.cc</tt></strong></p>
<p><strong><tt>output.o:  output.cc</tt></strong><br />
<strong><tt> g++ -c -Wall output.cc</tt></strong></p>
<p><strong><tt>process.o: process.cc</tt></strong><br />
<strong><tt> g++ -c -Wall process.cc</tt></strong></p>
<p><strong><tt>clean:</tt></strong><br />
<strong><tt> rm -f *.o core</tt></strong></p>
<p><strong><tt>distclean:</tt></strong><br />
<strong><tt> make clean</tt></strong><br />
<strong><tt> rm -f mirror</tt></strong></p>
<p><strong><tt>again:</tt></strong><br />
<strong><tt> make distclean</tt></strong><br />
<strong><tt> make mirror</tt></strong></td>
</tr>
</tbody>
</table>
<p>All object files are made using <tt>g++</tt>. On other machines that may be<tt> cxx, cpp, </tt>or something the like. So let&#8217;s define a macro for the C++ compiler:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++ = g++</tt></strong></td>
</tr>
</tbody>
</table>
<p>The command line options are also different for different compilers so it&#8217;s a good idea to have a macro for them:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++-Flags = -c -Wall</tt></strong></td>
</tr>
</tbody>
</table>
<p>On some machines the command to remove files is<tt> rm </tt>(or<tt> rm -f), </tt>on others<tt> del, </tt>some use<tt> delete, </tt>some<tt> erase, </tt>and some even<tt> discard.</tt>So that&#8217;s another candidate for a macro:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>RM = rm -f</tt></strong></td>
</tr>
</tbody>
</table>
<p>Even make may not always be called make (though I know of no system where this is the case):</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>MAKE = make</tt></strong></td>
</tr>
</tbody>
</table>
<p>In our example the linker is also g++. In general that need not be the case. So we define the following two macros:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>LINKER       = g++</tt></strong><br />
<strong><tt>LINKER-FLAGS = -o</tt></strong></td>
</tr>
</tbody>
</table>
<p>The meaning of the following two macros is obvious:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>OBJS   = input.o mirror.o process.o output.o</tt></strong><br />
<strong><tt>TARGET = mirror</tt></strong></td>
</tr>
</tbody>
</table>
<p>After these changes the present state of the Makefile is<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile6">Makefile6</a></strong>:</tt></p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++          = g++</tt></strong><br />
<strong><tt>C++-FLAGS    = -c -Wall</tt></strong><br />
<strong><tt>LINKER       = g++</tt></strong><br />
<strong><tt>LINKER-FLAGS = -o</tt></strong><br />
<strong><tt>RM           = rm -f</tt></strong><br />
<strong><tt>MAKE         = make</tt></strong><br />
<strong><tt>OBJS         = input.o mirror.o process.o output.o</tt></strong><br />
<strong><tt>TARGET       = mirror</tt></strong><strong><tt>.IGNORE:</tt></strong><br />
<strong><tt>.SILENT:</tt></strong></p>
<p><strong><tt>$(TARGET): $(OBJS)</tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $(TARGET) $(OBJS)</tt></strong></p>
<p><strong><tt>mirror.o:  mirror.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) mirror.cc</tt></strong></p>
<p><strong><tt>input.o:   input.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) input.cc</tt></strong></p>
<p><strong><tt>output.o:  output.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) output.cc</tt></strong></p>
<p><strong><tt>process.o: process.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) process.cc</tt></strong></p>
<p><strong><tt>clean:</tt></strong><br />
<strong><tt> $(RM) *.o core</tt></strong></p>
<p><strong><tt>distclean:</tt></strong><br />
<strong><tt> $(MAKE) clean</tt></strong><br />
<strong><tt> $(RM) $(TARGET)</tt></strong></p>
<p><strong><tt>again:</tt></strong><br />
<strong><tt> $(MAKE) distclean</tt></strong><br />
<strong><tt> $(MAKE) $(TARGET)</tt></strong></td>
</tr>
</tbody>
</table>
<h2><strong><span style="font-family: Arial,Helvetica">2. What are inference rules and what are they good for?</span></strong></h2>
<p>If you have a close look at the rules to make<tt> mirror.o, input.o, output.o, </tt>and<tt> process.o</tt> you see that they are all the same:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>&lt;filename&gt;.o: &lt;filename&gt;.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) &lt;filename&gt;.cc</tt></strong></td>
</tr>
</tbody>
</table>
<p>To avoid all these lenthy entries in a Makefile there are inference rules: They describe the &#8217;standard procedure&#8217; of making files of type b from files of type a. In this case the rule to make an object file from a given C++ file is</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.cc.o:</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $&lt;</tt></strong></td>
</tr>
</tbody>
</table>
<p>or alternatively you could use</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.cc.o:</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $*.cc</tt></strong></td>
</tr>
</tbody>
</table>
<p>It&#8217;s easy to see what<tt> $&lt; </tt>and<tt> $* </tt>mean but I&#8217;ll come back to that in just a moment. First I will change the rule for making the target &#8216;mirror&#8217; so that it makes use of another strange-looking predefined macros:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>$(TARGET): $(OBJS)</tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $@ $(OBJ)</tt></strong></td>
</tr>
</tbody>
</table>
<p>Now let&#8217;s have a look at the meaning of <tt>$*, $&lt;, </tt>and<tt> $@:</tt></p>
<p><strong><tt>$*</tt></strong> ist the current target without an extension (the base file name) with path. For example, in</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>input.o: input.cc</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $*.cc</tt></strong></td>
</tr>
</tbody>
</table>
<p>the value of<strong><tt> $* </tt></strong>is <strong><tt>input</tt></strong>.<strong><tt> $* </tt></strong>is commonly used only in inference rules and command lines.</p>
<p><tt><strong>$@</strong> </tt>is the current target (including extension, if any). For example, in</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>mirror: $(OBJS)</tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $@ $(OBJS)</tt></strong></td>
</tr>
</tbody>
</table>
<p>the value of<tt> <strong>$@</strong> </tt>is<strong><tt> mirror</tt></strong>.</p>
<p><strong><tt>$&lt;</tt></strong> is a dependent file out-of date with the target file. For example,</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.cc.o:</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $*.cc</tt></strong></td>
</tr>
</tbody>
</table>
<p>Notice that <strong><tt>$&lt;</tt></strong>, in an inference rule such as <strong><tt>.cc.o</tt></strong>, is equivalent to <strong><tt>$*.cc</tt></strong> (as already mentioned).</p>
<p>Just to remind you: Your Makefile should now look like<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile7">Makefile7</a></strong></tt>:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++          = g++</tt></strong><br />
<strong><tt>C++-FLAGS    = -c -Wall</tt></strong><br />
<strong><tt>LINKER       = g++</tt></strong><br />
<strong><tt>LINKER-FLAGS = -o</tt></strong><br />
<strong><tt>RM           = rm -f</tt></strong><br />
<strong><tt>MAKE         = make</tt></strong><br />
<strong><tt>OBJS         = input.o mirror.o process.o output.o</tt></strong><br />
<strong><tt>TARGET       = mirror</tt></strong><strong><tt>.IGNORE:</tt></strong><br />
<strong><tt>.SILENT:</tt></strong></p>
<p><strong><tt>$(TARGET): $(OBJS)</tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $@ $(OBJS)</tt></strong></p>
<p><strong><tt>.cc.o:</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $&lt;</tt></strong></p>
<p><strong><tt>clean:</tt></strong><br />
<strong><tt> $(RM) *.o core</tt></strong></p>
<p><strong><tt>distclean:</tt></strong><br />
<strong><tt> $(MAKE) clean</tt></strong><br />
<strong><tt> $(RM) $(TARGET)</tt></strong></p>
<p><strong><tt>again:</tt></strong><br />
<strong><tt> $(MAKE) distclean</tt></strong><br />
<strong><tt> $(MAKE) $(TARGET)</tt></strong></td>
</tr>
</tbody>
</table>
<h2><span style="font-family: Arial,Helvetica">3. Continuation lines</span></h2>
<p>If your project consists of a great number of files (or you need lots of options) you may wish to split lines. Another reason for splitting lines is increasing the readability of your Makefile (don&#8217;t underestimate that point!).  In<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile7">Makefile7</a></strong> </tt>you could change the line reading</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>OBJS = input.o mirror.o process.o output.o</tt></strong></td>
</tr>
</tbody>
</table>
<p>to read</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>OBJS = input.o   \</tt></strong><br />
<strong><tt> mirror.o  \</tt></strong><br />
<strong><tt> process.o \</tt></strong><br />
<strong><tt> output.o</tt></strong></td>
</tr>
</tbody>
</table>
<h2><span style="font-family: Arial,Helvetica">4.  Comments</span></h2>
<p>You can also add comments to your Makefile like the ones in<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile8">Makefile8</a></strong></tt>:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++          = g++           # use GNU C++ compiler </tt></strong><br />
<strong><tt>C++-FLAGS    = -c -Wall      # warn all </tt></strong><br />
<strong><tt>LINKER       = g++           # use GNU C++ as linker </tt></strong><br />
<strong><tt>LINKER-FLAGS = -o            # flags for linker </tt></strong><br />
<strong><tt>RM           = rm -f         # how to remove files </tt></strong><br />
<strong><tt>MAKE         = make          # name of make utility </tt></strong><br />
<strong><tt># you cannot add comments after the continuation character! </tt></strong><br />
<strong><tt>OBJS         = input.o   \ </tt></strong><br />
<strong><tt> mirror.o  \ </tt></strong><br />
<strong><tt> process.o \ </tt></strong><br />
<strong><tt> output.o </tt></strong><br />
<strong><tt>TARGET       = mirror        # name of executable </tt></strong><strong><tt>.IGNORE:                     # ignore problems (as far as possible) </tt></strong><br />
<strong><tt>.SILENT:                     # don't echo commands executed </tt></strong></p>
<p><strong><tt>$(TARGET):  $(OBJS) </tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $@ $(OBJS) </tt></strong></p>
<p><strong><tt>.cc.o: </tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $&lt; </tt></strong></p>
<p><strong><tt># remove object files and core (if any) </tt></strong><br />
<strong><tt>clean: </tt></strong><br />
<strong><tt> $(RM) *.o core </tt></strong></p>
<p><strong><tt># remove object files, core dump, and executable (if any) </tt></strong><br />
<strong><tt>distclean: </tt></strong><br />
<strong><tt> $(MAKE) clean </tt></strong><br />
<strong><tt> $(RM) $(TARGET) </tt></strong></p>
<p><strong><tt># remove object files, core dump, and executable (if any) and </tt></strong><br />
<strong><tt># make them again. </tt></strong><br />
<strong><tt>again: </tt></strong><br />
<strong><tt> $(MAKE) distclean </tt></strong><br />
<strong><tt> $(MAKE) $(TARGET)</tt></strong></td>
</tr>
</tbody>
</table>
<h2><span style="font-family: Arial,Helvetica">5. The .SUFFIXES pseudo target</span></h2>
<p>make comes with a couple of predefined rules how to make certain files. To get rid of them simply use</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.SUFFIXES:</tt></strong></td>
</tr>
</tbody>
</table>
<p>If you do that you have to list all suffixes that your Makefile does support. In the above case that would be</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>.SUFFIXES: .o .cc</tt></strong></td>
</tr>
</tbody>
</table>
<p>You can also use<strong><tt> .SUFFIXES </tt></strong>to add rules to the predefined ones (in precisely the same manner as in the example above).</p>
<h2><span style="font-family: Arial,Helvetica">6. Using environment variables</span></h2>
<p>You can use environment variables in the same way as macros (besides that they are defined outside the Makefile):</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>info:</tt></strong><br />
<strong><tt> echo $(USER)</tt></strong></td>
</tr>
</tbody>
</table>
<p>Surely this is not a very useful example. Finding more useful ones is left to the reader.  Now, your Makefile should look like<tt> <strong><a href="http://www-cip.physik.uni-bonn.de/pool/infos/make/Makefile9">Makefile9</a></strong></tt>:</p>
<table border="1" cellpadding="20" width="100%" bgcolor="#ffffbf">
<tbody>
<tr>
<td><strong><tt>C++          = g++           # use GNU C++ compiler</tt></strong><br />
<strong><tt>C++-FLAGS    = -c -Wall      # warn all</tt></strong><br />
<strong><tt>LINKER       = g++           # use GNU C++ as linker </tt></strong><br />
<strong><tt>LINKER-FLAGS = -o            # flags for linker</tt></strong><br />
<strong><tt>RM           = rm -f         # how to remove files</tt></strong><br />
<strong><tt>MAKE         = make          # name of make utility</tt></strong><br />
<strong><tt># you cannot add comments after the continuation character!</tt></strong><br />
<strong><tt>OBJS         = input.o   \</tt></strong><br />
<strong><tt> mirror.o  \</tt></strong><br />
<strong><tt> process.o \</tt></strong><br />
<strong><tt> output.o</tt></strong><br />
<strong><tt>TARGET       = mirror        # name of executable</tt></strong><strong><tt>.IGNORE:                     # ignore problems (as far as possible)</tt></strong><br />
<strong><tt>.SILENT:                     # don't echo commands executed</tt></strong><br />
<strong><tt>.SUFFIXES:                   # get rid of predefined rules</tt></strong><br />
<strong><tt>.SUFFIXES: .cc .o</tt></strong></p>
<p><strong><tt>$(TARGET): $(OBJS)</tt></strong><br />
<strong><tt> $(LINKER) $(LINKER-FLAGS) $@ $(OBJS)</tt></strong></p>
<p><strong><tt>.cc.o:</tt></strong><br />
<strong><tt> $(C++) $(C++-FLAGS) $&lt;</tt></strong></p>
<p><strong><tt># remove object files and core (if any)</tt></strong><br />
<strong><tt>clean:</tt></strong><br />
<strong><tt> $(RM) *.o core</tt></strong></p>
<p><strong><tt># remove object files, core dump, and executable (if any)</tt></strong><br />
<strong><tt>distclean:</tt></strong><br />
<strong><tt> $(MAKE) clean</tt></strong><br />
<strong><tt> $(RM) $(TARGET)</tt></strong></p>
<p><strong><tt># remove object files, core dump, and executable (if any) and</tt></strong><br />
<strong><tt># make them again.</tt></strong><br />
<strong><tt>again:</tt></strong><br />
<strong><tt> $(MAKE) distclean</tt></strong><br />
<strong><tt> $(MAKE) $(TARGET)</tt></strong></p>
<p><strong><tt># echo username</tt></strong><br />
<strong><tt>info:</tt></strong><br />
<strong><tt> echo User is: $(USER)</tt></strong></td>
</tr>
</tbody>
</table>
<hr noshade="noshade" />Last changed tuesday 6/2/1998</p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/01/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-makefile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>วิธี ที่พึงระลึกถึงขณะใช้ JQuery</title>
		<link>http://www.memoball.info/06/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a3%e0%b9%87%e0%b8%a7-jquer/</link>
		<comments>http://www.memoball.info/06/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a3%e0%b9%87%e0%b8%a7-jquer/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 03:23:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.memoball.info/?p=317</guid>
		<description><![CDATA[บทความนี้จะกล่าวถึงการใช้ jQuery ที่ถูกต้องเพื่อเพิ่มประสิทธิภาพในการทำงานของตัว script ที่เราเขียนให้มีประสิทธิภาพสูงสุด

จาก WikiBall


			




เนื้อหา


1 ใช้เวอร์ชั่นใหม่สุด
2 ใช้ For แทน Each
3 รวมสคริปซะ
4 ใช้ ID แทน Class
5 เก็บไว้ในตัวแปร
6 หลีกเลี่ยงการใช้ DOM Manipulation
7 ใส่ return false ด้วย
8 ใช้ join แทน concat
9 reference




 if (window.showTocToggle) { var tocShowText = "แสดง"; var tocHideText = "ซ่อน"; showTocToggle(); } 

 ใช้เวอร์ชั่นใหม่สุด
แน่นอนเสียเหลือเกินว่าของใหม่ย่อมดีกว่าของเก่า ดังนั้นเราจึงควรใช้ jQuery ในเวอร์ชั่นที่ใหม่กว่า

&#60;!-- get the API with a simple script tag [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้จะกล่าวถึงการใช้ jQuery ที่ถูกต้องเพื่อเพิ่มประสิทธิภาพในการทำงานของตัว script ที่เราเขียนให้มีประสิทธิภาพสูงสุด<span id="more-317"></span></p>
<div id="bodyContent">
<h3 id="siteSub"><a href="http://wiki.memoball.info/index.php/Increase_jQuery_performance">จาก WikiBall</a></h3>
<div id="contentSub"></div>
<div id="jump-to-nav"></div>
<p>			<!-- start content --></p>
<table id="toc" class="toc" summary="เนื้อหา">
<tr>
<td>
<div id="toctitle">
<h2>เนื้อหา</h2>
</div>
<ul>
<li class="toclevel-1"><a href="./#.E0.B9.83.E0.B8.8A.E0.B9.89.E0.B9.80.E0.B8.A7.E0.B8.AD.E0.B8.A3.E0.B9.8C.E0.B8.8A.E0.B8.B1.E0.B9.88.E0.B8.99.E0.B9.83.E0.B8.AB.E0.B8.A1.E0.B9.88.E0.B8.AA.E0.B8.B8.E0.B8.94" ref="toc"><span class="tocnumber">1</span> <span class="toctext">ใช้เวอร์ชั่นใหม่สุด</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B9.83.E0.B8.8A.E0.B9.89_For_.E0.B9.81.E0.B8.97.E0.B8.99_Each" ref="toc"><span class="tocnumber">2</span> <span class="toctext">ใช้ For แทน Each</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B8.A3.E0.B8.A7.E0.B8.A1.E0.B8.AA.E0.B8.84.E0.B8.A3.E0.B8.B4.E0.B8.9B.E0.B8.8B.E0.B8.B0" ref="toc"><span class="tocnumber">3</span> <span class="toctext">รวมสคริปซะ</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B9.83.E0.B8.8A.E0.B9.89_ID_.E0.B9.81.E0.B8.97.E0.B8.99_Class" ref="toc"><span class="tocnumber">4</span> <span class="toctext">ใช้ ID แทน Class</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B9.80.E0.B8.81.E0.B9.87.E0.B8.9A.E0.B9.84.E0.B8.A7.E0.B9.89.E0.B9.83.E0.B8.99.E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B9.81.E0.B8.9B.E0.B8.A3" ref="toc"><span class="tocnumber">5</span> <span class="toctext">เก็บไว้ในตัวแปร</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B8.AB.E0.B8.A5.E0.B8.B5.E0.B8.81.E0.B9.80.E0.B8.A5.E0.B8.B5.E0.B9.88.E0.B8.A2.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B9.83.E0.B8.8A.E0.B9.89_DOM_Manipulation" ref="toc"><span class="tocnumber">6</span> <span class="toctext">หลีกเลี่ยงการใช้ DOM Manipulation</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B9.83.E0.B8.AA.E0.B9.88_return_false_.E0.B8.94.E0.B9.89.E0.B8.A7.E0.B8.A2" ref="toc"><span class="tocnumber">7</span> <span class="toctext">ใส่ return false ด้วย</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B9.83.E0.B8.8A.E0.B9.89_join_.E0.B9.81.E0.B8.97.E0.B8.99_concat" ref="toc"><span class="tocnumber">8</span> <span class="toctext">ใช้ join แทน concat</span></a></li>
<li class="toclevel-1"><a href="./#reference" ref="toc"><span class="tocnumber">9</span> <span class="toctext">reference</span></a></li>
</ul>
</td>
</tr>
</table>
<p><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "แสดง"; var tocHideText = "ซ่อน"; showTocToggle(); } </script><br />
<a name=".E0.B9.83.E0.B8.8A.E0.B9.89.E0.B9.80.E0.B8.A7.E0.B8.AD.E0.B8.A3.E0.B9.8C.E0.B8.8A.E0.B8.B1.E0.B9.88.E0.B8.99.E0.B9.83.E0.B8.AB.E0.B8.A1.E0.B9.88.E0.B8.AA.E0.B8.B8.E0.B8.94" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">ใช้เวอร์ชั่นใหม่สุด</span></h2>
<p>แน่นอนเสียเหลือเกินว่าของใหม่ย่อมดีกว่าของเก่า ดังนั้นเราจึงควรใช้ jQuery ในเวอร์ชั่นที่ใหม่กว่า
</p>
<pre name="code" class="html">&lt;!-- get the API with a simple script tag --&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;&lt;a href=&quot;http://www.google.com/jsapi%22%3E%3C/script&quot;&gt;http://www.google.com/jsapi&quot;&gt;&lt;/script&lt;/a&gt;&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
     /* and load minified jQuery v1.3.2 this way */
     google.load (&quot;jquery&quot;, &quot;1.3.2&quot;, {uncompressed: false});  

     google.setOnLoadCallback (onLoad);
 &lt;/script&gt;</pre>
<p><a name=".E0.B9.83.E0.B8.8A.E0.B9.89_For_.E0.B9.81.E0.B8.97.E0.B8.99_Each" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">ใช้ For แทน Each</span></h2>
<p><a name=".E0.B8.A3.E0.B8.A7.E0.B8.A1.E0.B8.AA.E0.B8.84.E0.B8.A3.E0.B8.B4.E0.B8.9B.E0.B8.8B.E0.B8.B0" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">รวมสคริปซะ</span></h2>
<p>รวมสคริปของทุกเพจไว้ด้วยกัน เพื่อที่จะให้บราวเซอร์โหลดแค่ครั้งเดียว<br />
<a name=".E0.B9.83.E0.B8.8A.E0.B9.89_ID_.E0.B9.81.E0.B8.97.E0.B8.99_Class" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">ใช้ ID แทน Class</span></h2>
<p>ในการใช้ selecter ของ jQuery ควรจะใช้เลือกโดย ID แทนการเลือกด้วย class เช่น $(&#8217;#demo&#8217;) แทนการใช้ $(&#8217;.example&#8217;) ดังนั้นเราจึงควรเขียน HTML ใช้สนับสนุนการใช้งานในส่วนนี้ด้วย หรือถ้าจำเป็นต้องใช้ class จริงๆ ควรทำการสโคปการค้นหาให้เล็กลงเช่น  $(&#8217;.class&#8217;, &#8216;#class-container&#8217;)</p>
<pre>$(expression, context)  </pre>
<li><a name=".E0.B9.80.E0.B8.81.E0.B9.87.E0.B8.9A.E0.B9.84.E0.B8.A7.E0.B9.89.E0.B9.83.E0.B8.99.E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B9.81.E0.B8.9B.E0.B8.A3" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">เก็บไว้ในตัวแปร</span></h2>
<p>อย่าทำการ select หลายครั้งที่เหมือนกัน เพราะจะทำให้เปลืองโหลดขณะทำการ select ดังนั้นเราควรที่จะเก็บใส่ตัวแปรของเราซะ</p>
<pre name="code" class="javascript">
$('#demo').html ('What's up');
$('#demo').css ('color', '#444444');
$('#demo').addclass ('fulltext');
</pre>
<p>ควรใช้เป็น
</p>
<pre name="code" class="javascript">
var demo = $('#demo');
demo.html ('What's up');
demo.css ('color', '#444444');
demo.addclass ('fulltext');</pre>
<p>หรือ
</p>
<pre name="code" class="javascript"> $('#demo').css ('color', '#444444').addclass ('fulltext');
</pre>
<p><a name=".E0.B8.AB.E0.B8.A5.E0.B8.B5.E0.B8.81.E0.B9.80.E0.B8.A5.E0.B8.B5.E0.B9.88.E0.B8.A2.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B9.83.E0.B8.8A.E0.B9.89_DOM_Manipulation" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">หลีกเลี่ยงการใช้ DOM Manipulation</span></h2>
<p>หลีกเลี่ยงการใช้ function เกี่ยวกับการทำ DOM ใหม่ append(), after(),prepend() โดยการใช้ html() แทน<br />
<a name=".E0.B9.83.E0.B8.AA.E0.B9.88_return_false_.E0.B8.94.E0.B9.89.E0.B8.A7.E0.B8.A2" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">ใส่ return false ด้วย</span></h2>
<p>Function ที่ไม่มีการ return ใดๆ กลับมาเลย ควรเพิ่ม return false ด้วย<br />
<a name=".E0.B9.83.E0.B8.8A.E0.B9.89_join_.E0.B9.81.E0.B8.97.E0.B8.99_concat" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">ใช้ join แทน concat</span></h2>
<p>ถ้าข้อความเป็น array ควรใช้ join แทนการใช้ array มาบวกกัน<br />
<a name="reference" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline"> reference </span></h2>
<p><a href="http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/" class="external free" title="http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/" rel="nofollow">http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/</a>
</p>
<p><!--<br />
NewPP limit report<br />
Preprocessor node count: 26/1000000<br />
Post-expand include size: 0/2097152 bytes<br />
Template argument size: 0/2097152 bytes<br />
Expensive parser function count: 0/100<br />
--></p>
<p><!-- Saved in parser cache with key memoball_wiki:pcache:idhash:61-0!1!0!!th!2!edit=0 and timestamp 20090825081353 --></p>
<div class="printfooter">
<h5>รับข้อมูลจาก (Reference) : </h5>
<p>จาก WikiBall : <a href="http://wiki.memoball.info/index.php/Increase_jQuery_performance">http://wiki.memoball.info/index.php/Increase_jQuery_performance</a></div>
<div id='catlinks' class='catlinks'>
<div id="mw-normal-catlinks"><a href="http://wiki.memoball.info//index.php/%E0%B8%9E%E0%B8%B4%E0%B9%80%E0%B8%A8%E0%B8%A9:Categories" title="พิเศษ:Categories">หมวดหมู่</a>:&#32;<span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:JQuery&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:JQuery (ยังไม่ได้สร้าง)">JQuery</a></span> | <span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:Javascript&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:Javascript (ยังไม่ได้สร้าง)">Javascript</a></span></div>
</div>
<p>			<!-- end content --></p>
<div class="visualClear"></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/06/%e0%b9%80%e0%b8%9e%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%84%e0%b8%a7%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a3%e0%b9%87%e0%b8%a7-jquer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การทำ 3D tag cloud โดยใช้ jsTagCloud Plugin (jQuery)</title>
		<link>http://www.memoball.info/06/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%97%e0%b8%b3-3d-tag-cloud-%e0%b9%82%e0%b8%94%e0%b8%a2%e0%b9%83%e0%b8%8a%e0%b9%89-jstagcloud-plugin-jquery/</link>
		<comments>http://www.memoball.info/06/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%97%e0%b8%b3-3d-tag-cloud-%e0%b9%82%e0%b8%94%e0%b8%a2%e0%b9%83%e0%b8%8a%e0%b9%89-jstagcloud-plugin-jquery/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 03:01:56 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://memoball.nabzer.com/?p=302</guid>
		<description><![CDATA[วันนี้ได้วิธีทำ tag cloud แบบสามมิติ เอาไว้ทำเล่นๆ ให้สวยงาม จึงเก็บไว้เป็นบันทึก แต่ยังไม่ได้แกะซอร์ส เลยยังไม่รู้ว่าจะมีผลต่อการทำ SEO หรือไม่


จาก WikiBall


			




เนื้อหา


1 Features
2 Download and demo
3 Example
4 Reference




 if (window.showTocToggle) { var tocShowText = "แสดง"; var tocHideText = "ซ่อน"; showTocToggle(); } 

 Features

 เป็น Plugin สำหรับ Jquery

 เป็น 3D Cloud Navigator ใช้ร่วมกับ mouse

 เป็น link



 Download and demo

 https://projektserver.se/svn/tiny/javascript/jsTagCloud/

 http://slackers.se/resources/demo/jsTagCloud/demo.html



 Example

&#60;title&#62;jsTagCloud: 3D Tag Cloud using [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ได้วิธีทำ tag cloud แบบสามมิติ เอาไว้ทำเล่นๆ ให้สวยงาม จึงเก็บไว้เป็นบันทึก แต่ยังไม่ได้แกะซอร์ส เลยยังไม่รู้ว่าจะมีผลต่อการทำ SEO หรือไม่<br />
<span id="more-302"></span></p>
<div id="bodyContent">
<h3 id="siteSub"><a href="http://wiki.memoball.info/index.php/3D_tag_cloud_%28jsTagCloud_Plugin%29_by_Jquery">จาก WikiBall</a></h3>
<div id="contentSub"></div>
<div id="jump-to-nav"></div>
<p>			<!-- start content --></p>
<table id="toc" class="toc" summary="เนื้อหา">
<tr>
<td>
<div id="toctitle">
<h2>เนื้อหา</h2>
</div>
<ul>
<li class="toclevel-1"><a href="./#Features" ref="toc"><span class="tocnumber">1</span> <span class="toctext">Features</span></a></li>
<li class="toclevel-1"><a href="./#Download_and_demo" ref="toc"><span class="tocnumber">2</span> <span class="toctext">Download and demo</span></a></li>
<li class="toclevel-1"><a href="./#Example" ref="toc"><span class="tocnumber">3</span> <span class="toctext">Example</span></a></li>
<li class="toclevel-1"><a href="./#Reference" ref="toc"><span class="tocnumber">4</span> <span class="toctext">Reference</span></a></li>
</ul>
</td>
</tr>
</table>
<p><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "แสดง"; var tocHideText = "ซ่อน"; showTocToggle(); } </script><br />
<a name="Features" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">Features</span></h2>
<ul>
<li> เป็น Plugin สำหรับ Jquery
</li>
<li> เป็น 3D Cloud Navigator ใช้ร่วมกับ mouse
</li>
<li> เป็น link
</li>
</ul>
<p><a name="Download_and_demo" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">Download and demo</span></h2>
<ul>
<li> <a href="https://projektserver.se/svn/tiny/javascript/jsTagCloud/" class="external free" title="https://projektserver.se/svn/tiny/javascript/jsTagCloud/" rel="nofollow">https://projektserver.se/svn/tiny/javascript/jsTagCloud/</a>
</li>
<li> <a href="http://slackers.se/resources/demo/jsTagCloud/demo.html" class="external free" title="http://slackers.se/resources/demo/jsTagCloud/demo.html" rel="nofollow">http://slackers.se/resources/demo/jsTagCloud/demo.html</a>
</li>
</ul>
<p><a name="Example" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">Example</span></h2>
<pre name="code" class="html">
&lt;title&gt;jsTagCloud: 3D Tag Cloud using jsTagCloud jQuery plugin&lt;/title&gt;
     google.load(&quot;jquery&quot;, &quot;1&quot;);
     google.setOnLoadCallback(function() {
             jQuery(&quot;#cloud&quot;).tagcloud({
                     'baseurl'&nbsp;: 'http://viralpatel.net/blogs/tag/',
                     'background'&nbsp;: [255,255,255],
                     'textcolor'&nbsp;: [0,0,128],
                     'interval'&nbsp;: 50,
                     'data'&nbsp;: [
                         {'url':'AJAX', 'tag':'AJAX'},
                         {'url':'browsers', 'tag':'browsers'},
                         {'url':'chrome', 'tag':'chrome'},
                         {'url':'Compression', 'tag':'Compression'},
                         {'url':'CSS', 'tag':'CSS'},
                         {'url':'exception', 'tag':'exception'},
                         {'url':'file-upload', 'tag':'file-upload'},
                         {'url':'firebug', 'tag':'firebug'},
                         {'url':'firefox', 'tag':'firefox'},
                         {'url':'gmail', 'tag':'gmail'},
                         {'url':'google', 'tag':'google'},
                         {'url':'internet', 'tag':'internet'},
                         {'url':'J2EE', 'tag':'J2EE'},
                         {'url':'jar', 'tag':'jar'},
                         {'url':'Java', 'tag':'Java'},
                         {'url':'JavaScript', 'tag':'JavaScript'},
                         {'url':'framework', 'tag':'framework'},
                         {'url':'java', 'tag':'java'},
                         {'url':'javascript', 'tag':'javascript'},
                         {'url':'jboss', 'tag':'jboss'},
                         {'url':'linux', 'tag':'linux'},
                         {'url':'JQuery', 'tag':'JQuery'},
                         {'url':'maven', 'tag':'maven'},
                         {'url':'pdf', 'tag':'pdf'},
                         {'url':'performance', 'tag':'performance'},
                         {'url':'rss', 'tag':'rss'},
                         {'url':'php', 'tag':'php'},
                         {'url':'servlet', 'tag':'servlet'},
                         {'url':'struts', 'tag':'struts'},
                         {'url':'stanford', 'tag':'stanford'},
                         {'url':'tomcat', 'tag':'tomcat'},
                         {'url':'twitter', 'tag':'twitter'},
                         {'url':'Web2.0', 'tag':'Web2.0'},
                         {'url':'ubuntu', 'tag':'ubuntu'},
                         {'url':'wordpress', 'tag':'wordpress'},
                         {'url':'windows', 'tag':'windows'}
                                 ]
                 });
     });
    &lt;br&gt;
</pre>
<p><a name="Reference" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline">Reference</span></h2>
<ul>
<li> <a href="http://slackers.se/2009/jstagcloud-js-canvas-3d-tag-cloud" class="external free" title="http://slackers.se/2009/jstagcloud-js-canvas-3d-tag-cloud" rel="nofollow">http://slackers.se/2009/jstagcloud-js-canvas-3d-tag-cloud</a>
</li>
</ul>
<p><!--<br />
NewPP limit report<br />
Preprocessor node count: 8/1000000<br />
Post-expand include size: 0/2097152 bytes<br />
Template argument size: 0/2097152 bytes<br />
Expensive parser function count: 0/100<br />
--></p>
<p><!-- Saved in parser cache with key memoball_wiki:pcache:idhash:57-0!1!0!!th!2!edit=0 and timestamp 20090825091057 --></p>
<div class="printfooter">
<h5>รับข้อมูลจาก (Reference) : </h5>
<p>จาก WikiBall : <a href="http://wiki.memoball.info/index.php/3D_tag_cloud_%28jsTagCloud_Plugin%29_by_Jquery">http://wiki.memoball.info/index.php/3D_tag_cloud_(jsTagCloud_Plugin)_by_Jquery</a></div>
<div id='catlinks' class='catlinks'>
<div id="mw-normal-catlinks"><a href="http://wiki.memoball.info//index.php/%E0%B8%9E%E0%B8%B4%E0%B9%80%E0%B8%A8%E0%B8%A9:Categories" title="พิเศษ:Categories">หมวดหมู่</a>:&#32;<span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:JQuery&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:JQuery (ยังไม่ได้สร้าง)">JQuery</a></span> | <span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:Javascript&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:Javascript (ยังไม่ได้สร้าง)">Javascript</a></span></div>
</div>
<p>			<!-- end content --></p>
<div class="visualClear"></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/06/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%97%e0%b8%b3-3d-tag-cloud-%e0%b9%82%e0%b8%94%e0%b8%a2%e0%b9%83%e0%b8%8a%e0%b9%89-jstagcloud-plugin-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP ก็สามารถทำ Multithreading/Parrallel-programing ได้</title>
		<link>http://www.memoball.info/05/php-%e0%b8%81%e0%b9%87%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b8%b2%e0%b8%a3%e0%b8%96%e0%b8%97%e0%b8%b3-multithreadingparrallel-programing-%e0%b9%84%e0%b8%94%e0%b9%89/</link>
		<comments>http://www.memoball.info/05/php-%e0%b8%81%e0%b9%87%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b8%b2%e0%b8%a3%e0%b8%96%e0%b8%97%e0%b8%b3-multithreadingparrallel-programing-%e0%b9%84%e0%b8%94%e0%b9%89/#comments</comments>
		<pubDate>Tue, 26 May 2009 04:21:42 +0000</pubDate>
		<dc:creator>spnball</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://memoball.nabzer.com/?p=289</guid>
		<description><![CDATA[เมื่อวานได้อ่านเรื่องการใช้ทำ multithreading ใน php เลยคิดว่าน่าสนใจ (http://codestips.com/php-multithreading-using-curl/) เพราะโดยปกติแล้วตัว php เองไม่สามารถทำการฟอร์ค thread ขึ้นมาได้เอง จึงทำการให้การทำงานในบางประเภททำได้ยากหรือไม่มีประสิทธิภาพ ซึ่งเมื่อได้อ่านแล้วก็รู้สึกว่ามีประโยชน์เป็นอย่างมาก ซึ่งอาจจะเขียน php_proxy ใน Napzer library ให้เป็นอย่างนี้ก็คงดี อย่างไรก็ตามผมยังห่วงเรื่องประสิทธิภาพในการทำงานว่ามันจะมีประสิทธิภาพมากแค่ไหน ซึ่งผมคิดว่ามันขึ้นอยู่กับการออกแบบ ซึ่งคงต้องลองทำการทดสอบกันดูในระดับหนึ่ง


จาก WikiBall


			
การเขียนแอพลิเคชั่นแบบ Parallel programming ใน PHP นั้นไม่สามารถทำได้โดยตรง เพราะ PHP ไม่มีความยุ่งยากในการจัดการเกี่ยวกับเรื่องของ threading จึงทำให้ง่ายต่อการเขียน แต่สำหรับงานบางอย่างแล้วการใช้การคำนวณแบบคูขนานก็มีความจำเป็นในการใช้งาน ไม่ว่าจะเป็นการทำงานอยู่บนเครื่องเดียวกัน หรือเครื่องอื่นก็ตาม เราจึงต้องหาวิธีการอื่นมาช่วย ซึ่งในที่นี้เราจะพูดถึงการใช้ cURL library มาช่วยในการจัดการ





เนื้อหา


1 ข้อดีของการทำ parrallel programming
2 uCURL กับการทำ multithreading
3 ตัวอย่างการใช้ cURL
4 ตัวอย่าง




 if (window.showTocToggle) { var tocShowText [...]]]></description>
			<content:encoded><![CDATA[<p>เมื่อวานได้อ่านเรื่องการใช้ทำ multithreading ใน php เลยคิดว่าน่าสนใจ (<a href="http://codestips.com/php-multithreading-using-curl/">http://codestips.com/php-multithreading-using-curl/</a>) เพราะโดยปกติแล้วตัว php เองไม่สามารถทำการฟอร์ค thread ขึ้นมาได้เอง จึงทำการให้การทำงานในบางประเภททำได้ยากหรือไม่มีประสิทธิภาพ ซึ่งเมื่อได้อ่านแล้วก็รู้สึกว่ามีประโยชน์เป็นอย่างมาก ซึ่งอาจจะเขียน php_proxy ใน Napzer library ให้เป็นอย่างนี้ก็คงดี อย่างไรก็ตามผมยังห่วงเรื่องประสิทธิภาพในการทำงานว่ามันจะมีประสิทธิภาพมากแค่ไหน ซึ่งผมคิดว่ามันขึ้นอยู่กับการออกแบบ ซึ่งคงต้องลองทำการทดสอบกันดูในระดับหนึ่ง<br />
<span id="more-289"></span></p>
<div id="bodyContent">
<h3 id="siteSub"><a href="http://wiki.memoball.info/index.php/PHP_multithreading_and_Parallel_programming_using_cURL">จาก WikiBall</a></h3>
<div id="contentSub"></div>
<div id="jump-to-nav"></div>
<p>			<!-- start content --></p>
<p>การเขียนแอพลิเคชั่นแบบ Parallel programming ใน PHP นั้นไม่สามารถทำได้โดยตรง เพราะ PHP ไม่มีความยุ่งยากในการจัดการเกี่ยวกับเรื่องของ threading จึงทำให้ง่ายต่อการเขียน แต่สำหรับงานบางอย่างแล้วการใช้การคำนวณแบบคูขนานก็มีความจำเป็นในการใช้งาน ไม่ว่าจะเป็นการทำงานอยู่บนเครื่องเดียวกัน หรือเครื่องอื่นก็ตาม เราจึงต้องหาวิธีการอื่นมาช่วย ซึ่งในที่นี้เราจะพูดถึงการใช้ cURL library มาช่วยในการจัดการ
</p>
<table id="toc" class="toc" summary="เนื้อหา">
<tr>
<td>
<div id="toctitle">
<h2>เนื้อหา</h2>
</div>
<ul>
<li class="toclevel-1"><a href="./#.E0.B8.82.E0.B9.89.E0.B8.AD.E0.B8.94.E0.B8.B5.E0.B8.82.E0.B8.AD.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B8.97.E0.B8.B3_parrallel_programming" ref="toc"><span class="tocnumber">1</span> <span class="toctext">ข้อดีของการทำ parrallel programming</span></a></li>
<li class="toclevel-1"><a href="./#uCURL_.E0.B8.81.E0.B8.B1.E0.B8.9A.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B8.97.E0.B8.B3_multithreading" ref="toc"><span class="tocnumber">2</span> <span class="toctext">uCURL กับการทำ multithreading</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B8.AD.E0.B8.A2.E0.B9.88.E0.B8.B2.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B9.83.E0.B8.8A.E0.B9.89_cURL" ref="toc"><span class="tocnumber">3</span> <span class="toctext">ตัวอย่างการใช้ cURL</span></a></li>
<li class="toclevel-1"><a href="./#.E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B8.AD.E0.B8.A2.E0.B9.88.E0.B8.B2.E0.B8.87" ref="toc"><span class="tocnumber">4</span> <span class="toctext">ตัวอย่าง</span></a></li>
</ul>
</td>
</tr>
</table>
<p><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "แสดง"; var tocHideText = "ซ่อน"; showTocToggle(); } </script><br />
<a name=".E0.B8.82.E0.B9.89.E0.B8.AD.E0.B8.94.E0.B8.B5.E0.B8.82.E0.B8.AD.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B8.97.E0.B8.B3_parrallel_programming" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline"> ข้อดีของการทำ parrallel programming </span></h2>
<p>การเขียนโปรแกรมแบบ parrallel นั้นเหมาะสมกับการทำงานบางอย่าง ซึ่งในคอมพิวเตอร์ของเราในปัจจุบันก็ใช้การทำงานลักษณะดังกล่าวในโปรแกรมหลายๆ ชนิด เช่น โปรแกรมทางด้านกราฟิก วิธีการนี้จะช่วยลดเวลาในการทำงานของกระบวนการหลักไปได้เป็นอย่างมาก เช่น เราแบ่งส่วนต่างๆ ของหน้าเวปของเราเป็น widget หรือ module ย่อยๆ แล้วในเครื่องแต่ละเครื่องทำงานในการสร้างโมดูลของตัวเองโดยเฉพาะ ซึ่งจะดีแค่ไหนที่เราสามารถเรียกใช้งาน module ต่างๆ นั้นได้พร้อมๆ กัน โดยไม่ต้องรอโหลดเรียงกันทีละ module โดยการเขียนโปรแกรมอย่างนี้จะทำให้ช่วยประหยัดเวลาสร้างข้อมูลที่จะต้องส่งให้ client ได้มาก และยังสามารถใช้ทรัพยากรที่มีอยู่ได้อย่างมีประสิทธิภาพสูงสุดอีกด้วย
</p>
<p><a name="uCURL_.E0.B8.81.E0.B8.B1.E0.B8.9A.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B8.97.E0.B8.B3_multithreading" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline"> uCURL กับการทำ multithreading </span></h2>
<p>uCURL นั้นโดยปกติแล้วไม่ถูกติดตั้งเข้ามาใน PHP มาก่อนแแต่จะมาเป็น extension เสริมสำหรับ PHP (โดยส่วนมากผู้ให้บริการ Host ทั่วไปจะทำการติดตั้งมาให้อยู่แล้ว) หนึ่งในความสามารถของ uCURL ที่น่าสนใจอย่างมากคือการทำ multi handle ซึ่งยอมให้สามารถทำ multiple cURL processing ในแบบ parallel ซึ่งฟังก์ชั่นสำคัญที่ต้องใข้ได้แก่
</p>
<ul>
<li> <b>curl_multi_init</b> &#8211; initialize a new cURL multi handle. It will return the cURL handle on success and FALSE on error.
</li>
<li> <b>curl_multi_add_handle</b> — Add a cURL handle to a cURL multi handle.
</li>
<li> <b>curl_multi_exec</b> — Runs all the curl handle in the cURL multi handle in parallel.
</li>
<li> <b>curl_multi_remove_handle</b> — Removes a cURL handle from a cURL multi handle.
</li>
<li> <b>curl_multi_close</b> — close the cURL multi handle.
</li>
</ul>
<p><a name=".E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B8.AD.E0.B8.A2.E0.B9.88.E0.B8.B2.E0.B8.87.E0.B8.81.E0.B8.B2.E0.B8.A3.E0.B9.83.E0.B8.8A.E0.B9.89_cURL" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline"> ตัวอย่างการใช้ cURL </span></h2>
<p>สร้างอเรย์สำหรับบ่งบอกว่า process ไหนจะทำที่ url ใด
</p>
<pre name="code" class="php">
$process[1] = &quot;http://www.example1.com&quot;;
$process[2] = &quot;ftp://example3.com&quot;;
$process[3] = &quot;http://www.example2.com&quot;;
</pre>
<p>สร้าง cURL และทำการกำหนด handles
</p>
<pre name="code" class="php">
$curlHandle = curl_multi_init();
for ($i = 1;$i &lt;= 3; $i++)
 $curl[$i] = addHandle($curlHandle,$process[$i]);
</pre>
<p>รัน process
</p>
<pre name="code" class="php">
ExecHandle($curlHandle);
</pre>
<p>รับ content จาก handle ต่างๆ
</p>
<pre name="code" class="php">
for ($i = 1;$i &lt;= 3; $i++)
{
 $content[$i] =  curl_multi_getcontent ($curl[$i]);
 echo $content[$i];
}
</pre>
<p>ปิด handles และ url
</p>
<pre name="code" class="php">
for ($i = 1;$i &lt;= 3; $i++)//remove the sub - handles
  curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);
</pre>
<p><a name=".E0.B8.95.E0.B8.B1.E0.B8.A7.E0.B8.AD.E0.B8.A2.E0.B9.88.E0.B8.B2.E0.B8.87" href="http://wiki.memoball.info/"></a><br />
<h2> <span class="mw-headline"> ตัวอย่าง </span></h2>
<pre name="code" class="php">
&lt;?
//add a url to the handler
function addHandle(&amp;$curlHandle,$url)
{
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($curlHandle,$cURL);
return $cURL;
}
//execute the handle until the flag passed
// to function is greater then 0
function ExecHandle(&amp;$curlHandle)
{
$flag=null;
do {
//fetch pages in parallel
    curl_multi_exec($curlHandle,$flag);
} while ($flag &gt; 0);
}

$list[1] = &quot;http://www.example1.com&quot;;
$list[2] = &quot;ftp://example.com&quot;;
$list[3] = &quot;http://www.example2.com&quot;;
$curlHandle = curl_multi_init();
for ($i = 1;$i &lt;= 3; $i++)
 $curl[$i] = addHandle($curlHandle,$list[$i]);
ExecHandle($curlHandle);
for ($i = 1;$i &lt;= 3; $i++)
{
 $text[$i] =  curl_multi_getcontent ($curl[$i]);
 echo $text[$i];
}
for ($i = 1;$i &lt;= 3; $i++)//remove the handles
  curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);
?&gt;
</pre>
<p>จาก <a href="http://codestips.com/php-multithreading-using-curl/" class="external free" title="http://codestips.com/php-multithreading-using-curl/" rel="nofollow">http://codestips.com/php-multithreading-using-curl/</a>
</p>
<p><a href="http://codestips.com/scripts/multithread.zip" class="external text" title="http://codestips.com/scripts/multithread.zip" rel="nofollow">Complete source</a>  <a href="http://www.memoball.info/wp-content/uploads/2009/05/multithread.zip" class="external text" title="http://www.memoball.info/wp-content/uploads/2009/05/multithread.zip" rel="nofollow">(Mirror)</a><br />
<b>ทำตัวหนา</b>
</p>
<p><!--<br />
NewPP limit report<br />
Preprocessor node count: 23/1000000<br />
Post-expand include size: 0/2097152 bytes<br />
Template argument size: 0/2097152 bytes<br />
Expensive parser function count: 0/100<br />
--></p>
<p><!-- Saved in parser cache with key memoball_wiki:pcache:idhash:55-0!1!0!!th!2!edit=0 and timestamp 20090825091057 --></p>
<div class="printfooter">
<h5>รับข้อมูลจาก (Reference) : </h5>
<p>จาก WikiBall : <a href="http://wiki.memoball.info/index.php/PHP_multithreading_and_Parallel_programming_using_cURL">http://wiki.memoball.info/index.php/PHP_multithreading_and_Parallel_programming_using_cURL</a></div>
<div id='catlinks' class='catlinks'>
<div id="mw-normal-catlinks"><a href="http://wiki.memoball.info//index.php/%E0%B8%9E%E0%B8%B4%E0%B9%80%E0%B8%A8%E0%B8%A9:Categories" title="พิเศษ:Categories">หมวดหมู่</a>:&#32;<span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:PHP&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:PHP (ยังไม่ได้สร้าง)">PHP</a></span></div>
</div>
<p>			<!-- end content --></p>
<div class="visualClear"></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/05/php-%e0%b8%81%e0%b9%87%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b8%b2%e0%b8%a3%e0%b8%96%e0%b8%97%e0%b8%b3-multithreadingparrallel-programing-%e0%b9%84%e0%b8%94%e0%b9%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
