<?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; PHP</title>
	<atom:link href="http://www.memoball.info/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.memoball.info</link>
	<description>All of my Memories</description>
	<lastBuildDate>Sun, 17 Jul 2011 10:31:01 +0000</lastBuildDate>
	<language>TH</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Memcache &amp; MySQL PHP Session Handler</title>
		<link>http://www.memoball.info/2010/03/25/memcache-mysql-php-session-handler/</link>
		<comments>http://www.memoball.info/2010/03/25/memcache-mysql-php-session-handler/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 04:19:56 +0000</pubDate>
		<dc:creator>memoball</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 ตรงกลาง เพราะเนื่องจากเริ่มมี [...]]]></description>
			<content:encoded><![CDATA[<p>ช่วงนี้กำลังหาโซลูชั้นเพื่อที่จะทำ centralized session ตรงกลาง เพราะเนื่องจากเริ่มมี web application หลายตัว และในบางส่วนจำเป็นต้องมีการใช้ session ร่วมกัน จึงหาการแก้ปัญหาที่ตอบโจทย์ดังกล่าวว่าจะมีการรวม session มาไว้ที่เดียวกันและมีประสิทธิภาพสูงสุดได้อย่างไร ซึ่งในโซลูชั่นสุดท้ายผมคงต้องขอไม่พูดถึง เพี่อเป็นความปลอดภัยของระบบ แต่จะกล่าวแค่เฉพาะแนวคิดเฉยๆ ครับ</p>
<p>การทำ 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 มาไว้ที่เดียวกันและมีประสิทธิภาพสูงสุดได้อย่างไร ซึ่งในโซลูชั่นสุดท้ายผมคงต้องขอไม่พูดถึง เพี่อเป็นความปลอดภัยของระบบ แต่จะกล่าวแค่เฉพาะแนวคิดเฉยๆ ครับ</p>
<p>การทำ 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/2010/03/25/memcache-mysql-php-session-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download file over SSL Error with Internet Explorer</title>
		<link>http://www.memoball.info/2010/02/02/download-file-over-ssl-error-with-internet-explorer/</link>
		<comments>http://www.memoball.info/2010/02/02/download-file-over-ssl-error-with-internet-explorer/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 00:20:14 +0000</pubDate>
		<dc:creator>memoball</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[PHP]]></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 ของ [...]]]></description>
			<content:encoded><![CDATA[<p>เมื่ออาทิตย์ก่อน ผมเจอปัญหาที่ทำอยู่ที่ทำงานครับ ซึ่งงานผมเป็น service ที่ทำงานอยู่บน SSL หรือพูดให้ฟังดูง่ายๆ คือ https นั้นเอง ปัญหาที่ผมกับผู้ใช้งานเซอร์วิชก็คือ ไม่สามารถดาวโหลดแฟ้มข้อมูลได้</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/2010/02/02/download-file-over-ssl-error-with-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP ก็สามารถทำ Multithreading/Parrallel-programing ได้</title>
		<link>http://www.memoball.info/2009/05/26/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/2009/05/26/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>memoball</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://memoball.memoball.com/?p=289</guid>
		<description><![CDATA[เมื่อวานได้อ่านเรื่องการใช้ทำ multithreading ใน php เลยคิดว่าน่าสนใจ (http://codestips.com/php-multithreading-using-curl/) เพราะโดยปกติแล้วตัว php เองไม่สามารถทำการฟอร์ค thread ขึ้นมาได้เอง จึงทำการให้การทำงานในบางประเภททำได้ยากหรือไม่มีประสิทธิภาพ ซึ่งเมื่อได้อ่านแล้วก็รู้สึกว่ามีประโยชน์เป็นอย่างมาก ซึ่งอาจจะเขียน php_proxy ใน Napzer library ให้เป็นอย่างนี้ก็คงดี อย่างไรก็ตามผมยังห่วงเรื่องประสิทธิภาพในการทำงานว่ามันจะมีประสิทธิภาพมากแค่ไหน ซึ่งผมคิดว่ามันขึ้นอยู่กับการออกแบบ ซึ่งคงต้องลองทำการทดสอบกันดูในระดับหนึ่ง]]></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 ให้เป็นอย่างนี้ก็คงดี อย่างไรก็ตามผมยังห่วงเรื่องประสิทธิภาพในการทำงานว่ามันจะมีประสิทธิภาพมากแค่ไหน ซึ่งผมคิดว่ามันขึ้นอยู่กับการออกแบบ ซึ่งคงต้องลองทำการทดสอบกันดูในระดับหนึ่ง</p>
<p><!--WIKI "#PHP multithreading and Parallel programming using cURL#"--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/2009/05/26/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>
		<item>
		<title>การสร้าง PHP Error Log</title>
		<link>http://www.memoball.info/2009/03/26/187/</link>
		<comments>http://www.memoball.info/2009/03/26/187/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 03:20:09 +0000</pubDate>
		<dc:creator>memoball</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://memoball.memoball.com/?p=187</guid>
		<description><![CDATA[วันนี้ได้ทำการจัดการเรื่อง error ของ php ไม่ให้แสดงบนหน้าเวป แต่ไปเก็บไว้ที่ file แทน ทำให้เพิ่มความปลอดภัยของเวปไซต์เราและยังสามารถทำการ debug โปรแกรมได้ง่ายด้วย]]></description>
			<content:encoded><![CDATA[<p>วันนี้ได้ทำการจัดการเรื่อง error ของ php ไม่ให้แสดงบนหน้าเวป แต่ไปเก็บไว้ที่ file แทน ทำให้เพิ่มความปลอดภัยของเวปไซต์เราและยังสามารถทำการ debug โปรแกรมได้ง่ายด้วย<br />
<!--WIKI "#การสร้าง PHP Error logs ใน .htaccess#"--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/2009/03/26/187/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

