<?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>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>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>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>
		<item>
		<title>การสร้าง PHP Error Log</title>
		<link>http://www.memoball.info/03/187/</link>
		<comments>http://www.memoball.info/03/187/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 03:20:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://memoball.nabzer.com/?p=187</guid>
		<description><![CDATA[วันนี้ได้ทำการจัดการเรื่อง error ของ php ไม่ให้แสดงบนหน้าเวป แต่ไปเก็บไว้ที่ file แทน ทำให้เพิ่มความปลอดภัยของเวปไซต์เราและยังสามารถทำการ debug โปรแกรมได้ง่ายด้วย 

จาก WikiBall


			
			
 ปิดไม่ให้แสดง error

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off


 แสดง error ใน logs file

# enable PHP error logging
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log


 จัดการ permission ของ logs

# prevent access to PHP error log
&#60;Files PHP_errors.log&#62;
 Order allow,deny
 Deny from all
 [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ได้ทำการจัดการเรื่อง error ของ php ไม่ให้แสดงบนหน้าเวป แต่ไปเก็บไว้ที่ file แทน ทำให้เพิ่มความปลอดภัยของเวปไซต์เราและยังสามารถทำการ debug โปรแกรมได้ง่ายด้วย <span id="more-187"></span></p>
<div id="bodyContent">
<h3 id="siteSub"><a href="http://wiki.memoball.info/index.php/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87_PHP_Error_logs_%E0%B9%83%E0%B8%99_.htaccess">จาก WikiBall</a></h3>
<div id="contentSub"></div>
<div id="jump-to-nav"></div>
<p>			<!-- start content --><br />
			<a name=".E0.B8.9B.E0.B8.B4.E0.B8.94.E0.B9.84.E0.B8.A1.E0.B9.88.E0.B9.83.E0.B8.AB.E0.B9.89.E0.B9.81.E0.B8.AA.E0.B8.94.E0.B8.87_error" href="http://wiki.memoball.info/"></a><br />
<h3> <span class="mw-headline">ปิดไม่ให้แสดง error</span></h3>
<pre>
# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
</pre>
<p><a name=".E0.B9.81.E0.B8.AA.E0.B8.94.E0.B8.87_error_.E0.B9.83.E0.B8.99_logs_file" href="http://wiki.memoball.info/"></a><br />
<h3> <span class="mw-headline">แสดง error ใน logs file</span></h3>
<pre>
# enable PHP error logging
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log
</pre>
<p><a name=".E0.B8.88.E0.B8.B1.E0.B8.94.E0.B8.81.E0.B8.B2.E0.B8.A3_permission_.E0.B8.82.E0.B8.AD.E0.B8.87_logs" href="http://wiki.memoball.info/"></a><br />
<h3> <span class="mw-headline">จัดการ permission ของ logs</span></h3>
<pre>
# prevent access to PHP error log
&lt;Files PHP_errors.log&gt;
 Order allow,deny
 Deny from all
 Satisfy All
&lt;/Files&gt;
</pre>
<p><!--<br />
NewPP limit report<br />
Preprocessor node count: 13/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:37-0!1!0!!th!2!edit=0 and timestamp 20090825115815 --></p>
<div class="printfooter">
<h5>รับข้อมูลจาก (Reference) : </h5>
<p>จาก WikiBall : <a href="http://wiki.memoball.info/index.php/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87_PHP_Error_logs_%E0%B9%83%E0%B8%99_.htaccess">http://wiki.memoball.info/index.php/การสร้าง_PHP_Error_logs_ใน_.htaccess</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:Linux&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:Linux (ยังไม่ได้สร้าง)">Linux</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: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/03/187/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
