<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss version="2.0">
<channel>
<title><![CDATA[服务器开发(Server Development)]]></title> 
<link>http://www.libing.net.cn/index.php</link> 
<description><![CDATA[服务器开发 UDP服务器开发 TCP服务器开发 游戏服务器开发 IOCP 服务器设计]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[服务器开发(Server Development)]]></copyright>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/libing" type="application/rss+xml" /><item>
<link>http://www.libing.net.cn/post/nginx-windows.php</link>
<title><![CDATA[今天为商都服务器配置了Nginx图片服务器]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[服务器开发]]></category>
<pubDate>Sat, 02 May 2009 15:33:14 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/nginx-windows.php</guid> 
<description>
<![CDATA[ 
	一直很钦佩Nginx服务器对静态页面以及图片CSS的处理效率，商都目前的图片数量也增加到了一定的数量，图片处理一直就不是Apache的强项，又考虑到系统是windows 2003的Server，所以使用了windows 下的Nginx系统。<br/><br/>需要注意的是没有配置Fast-cgi解析，会导致PHP出现直接源代码下载到客户端，需要做屏蔽。另外需要注意的是系统注销以后，会导致Nginx程序关闭，需要注册服务。<br/><br/>所有文件下载链接：<br/><a href="attachment.php?fid=185">点击这里下载文件</a><br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/nginx/" rel="tag">nginx</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/multi-process-server-and-multi-thread-server.php</link>
<title><![CDATA[进程服务器模型和线程服务器模型]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[服务器开发]]></category>
<pubDate>Sat, 02 May 2009 11:50:46 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/multi-process-server-and-multi-thread-server.php</guid> 
<description>
<![CDATA[ 
	进程服务器模型和线程服务器模型<br/>作者：长春优狐科技开发有限公司 胡章优<br/>关键字：进程服务器 线程服务器 nginx apache<br/><a href="attachment.php?fid=184">点击这里下载文件</a><br/><br/>服务器开发中模型的选择是决定程序运行的关键因素，最近开发的一个Linux下BT下载均衡器则抛弃了多线程模型，而采用了多进程模型，在不同的模型的选择过程中，自然涉及到了各自的优势和劣势。<br/>多进程模型服务器具有以下特点：<br/>&nbsp;&nbsp;系统对立，功能清晰明显，可以同时启动多个进程，以提高系统的输出能力。<br/>&nbsp;&nbsp;系统需要处理好进程间数据共享问题。<br/>多线程模型服务器具有如下特点：<br/>&nbsp;&nbsp;系统线程间数据共享方便，开发相对简单，而线程间互斥以及全局数据的互斥可能也是造成系统瓶颈的一个关键因素。<br/>在网络服务器的开发过程中，参照木桶原理，系统的性能决定在瓶颈最大的那块木板上面。而在分析的过程中，网络IO部分无疑是那块最短的木板。<br/> <a href="http://www.libing.net.cn/attachment.php?fid=181" target="_blank"><img src="http://www.libing.net.cn/attachment.php?fid=181" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>图一：典型的多线程服务器模型程序流程图<br/>多线程服务器模型中，系统完成了初始化后，启动各自的线程，由全局队列保证各自的数据操作协调。伪数据结构及代码可以如下：<br/>[codes=c]<br/>Class System&#123;<br/>&nbsp;&nbsp;//接受客户端连接线程<br/>&nbsp;&nbsp;Static void AcceptThread();<br/>&nbsp;&nbsp;//数据操作线程，涉及到了socket的数据操作<br/>&nbsp;&nbsp;Static void DoDataThread();<br/>&nbsp;&nbsp;//辅助操作线程，比如数据库的缓存，批量入库等的<br/>&nbsp;&nbsp;Static void OtherThread();<br/>&nbsp;&nbsp;//保存客户端连接队列<br/>&nbsp;&nbsp;List<Client *> pLists;<br/>&nbsp;&nbsp;//数据库连接对象<br/>&nbsp;&nbsp;DBConnection dbConn;<br/>&nbsp;&nbsp;//全局服务器端socket<br/>&nbsp;&nbsp;Socket globalSock;<br/>&nbsp;&nbsp;//系统初始化<br/>&nbsp;&nbsp;Void Initial();<br/>&nbsp;&nbsp;//系统启动<br/>&nbsp;&nbsp;Void Start();<br/>&nbsp;&nbsp;//系统退出时清理资源<br/>&nbsp;&nbsp;Void Clean();<br/>&#125;;<br/>[/codes]<br/>如上伪代码阐述了多线程模型下，网络服务器开发的基本流程和数据结构相关。<br/> <a href="http://www.libing.net.cn/attachment.php?fid=182" target="_blank"><img src="http://www.libing.net.cn/attachment.php?fid=182" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>图二：典型的多进程服务器模型UML时序图<br/>合理的多进程调度管理程序应该根据当前负载压力情况，决定该启动的进程数量。<br/> <a href="http://www.libing.net.cn/attachment.php?fid=183" target="_blank"><img src="http://www.libing.net.cn/attachment.php?fid=183" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>图三：典型进程服务器模型执行图<br/>多进程的服务器程序涉及到了如下程序的开发：<br/>&nbsp;&nbsp;1：多进程调度服务器<br/>&nbsp;&nbsp;2：进程服务器<br/>调度服务器负责接收网络请求，并将请求转化为进程服务器需要的格式，后通过进程间通讯发送到进程服务器程序，后采用进程间通讯获取处理结果，使用网络IO发送给客户端。<br/>进程调度器在不同的平台上面处理方法可能不太一致：<br/>&nbsp;&nbsp;1：windows平台<br/>&nbsp;&nbsp;&nbsp;&nbsp;网络部分可以采用异步模式，如select或者IOCP。进程间通讯可以采用共享内存、SOCKET或者其他，视具体项目所要求的时间效率而定。<br/>&nbsp;&nbsp;2：Linux平台<br/>&nbsp;&nbsp;&nbsp;&nbsp;网络部分也采用异步模式，如select、/dev/poll、epoll。进程间通讯可以采用shm或者SOCKET之类。<br/>&nbsp;&nbsp;3：其他平台<br/>&nbsp;&nbsp;&nbsp;&nbsp;网络部分异步，如freebsd的kqueue。进程间通讯按照特定系统提供的最佳进程通讯而定。<br/>调度服务器考虑采用单线程执行，讲网络IO封装成为事件驱动机制，这样避免了线程间的互斥以及线程数据之间的锁定带来的负荷，可以大大的提高整个系统的效率和伸缩性。<br/>进程服务器使用进程间通讯模式，等待调度服务器发送来的特定数据，进行处理该数据，将结果再由进程间通讯方法发送给进程调度服务器。<br/>按照进程服务器和调度服务器的部署方式不同，系统模型也会有很大的区别。如果进程服务器和调度服务器部署在同一台服务器上面，可以采用的进程间通讯方法就比较多，而且也比较方便快速，但是并不是特别适合集群以及系统压力分解。优点是系统性能可以达到最佳状态。<br/>进程服务器和调度服务器部署在多台服务器上面的话，通讯的方式Socket为最佳。这种方式适合集群系统以及压力分解，缺点是系统的性能可能会较差。<br/>对调度服务器的伪代码模型如下：<br/>[codes=c]<br/>Class System&#123;<br/>&nbsp;&nbsp;//保存进程列表<br/>&nbsp;&nbsp;List<Process *> pLists;<br/>&nbsp;&nbsp;//保存客户端列表<br/>&nbsp;&nbsp;List<Client *> pClients;<br/>&nbsp;&nbsp;Socket sock;<br/>&nbsp;&nbsp;Void Initial();<br/>&nbsp;&nbsp;Void Start();<br/>&nbsp;&nbsp;Void Clean();<br/>&#125;<br/>[/codes]<br/>对象的主函数Start为系统关键函数：<br/>伪代码如下：<br/>[codes=c]<br/>Void Start()&#123;<br/>&nbsp;&nbsp;//启动N个进程服务器<br/>StartNProcess();<br/>&nbsp;&nbsp;//主线程循环<br/>&nbsp;&nbsp;While(flag)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;//获取Socket发生事件<br/>&nbsp;&nbsp;&nbsp;&nbsp;Event = GetClientEvent();<br/>&nbsp;&nbsp;&nbsp;&nbsp;Switch(event)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//客户端连接事件<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case ClientCome:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//更新客户端队列<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateClientList();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//收到客户端数据<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case GetClientData:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//获取数据<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetData();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//分析处理数据<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessData();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//使用进程间通讯发送给某个进程<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToAProcess();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//客户端离开<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case ClientGoes:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //更新客户端队列<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateClientList();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//客户端错误<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case ClientError:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateClientList();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//默认<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoSth();<br/>&nbsp;&nbsp;&nbsp;&nbsp; &#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp; //获取进程事件<br/>&nbsp;&nbsp;&nbsp;&nbsp; Event = GetProcessEvent();<br/>&nbsp;&nbsp;&nbsp;&nbsp; Switch(event)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//进程处理完数据<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case ParseData:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//发送给客户端<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToClient();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//错误<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case Error:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateProcessList();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default:<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoSth();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;//进程队列处理<br/>&nbsp;&nbsp;&nbsp;&nbsp;PerformProcessList();<br/>&nbsp;&nbsp;&nbsp;&nbsp;//客户端队列处理<br/>&nbsp;&nbsp;&nbsp;&nbsp;PerformClientList();<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>[/codes]<br/><br/>从上面的伪代码中，我们可以大致了解到进程调度服务器所需要处理的工作。<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;目前的WEB服务器apache可以通过配置文件的方式配置多种执行模式，包含：进程模式或者线程模式。<br/>&nbsp;&nbsp;另外由俄罗斯人开发的nginx web服务器以其极其优秀的性能，越来越受到大型运营商的青睐。而该服务器采用的就是进程服务器模型。通过配置多个PHP-FastCGI进程服务器程序，可以极大的提高动态web服务器的性能。<br/><br/>胡章优，吉林大学教师，博士，长春优狐科技开发有限公司总经理。专注于服务器开发，集群web服务器配置管理，系统安全配置，CDN网络架设以及机械电子控制系统开发。<br/>个人博客：http://doserver.net<br/><br/>参考文献：<br/>&nbsp;&nbsp;进程服务器<br/>&nbsp;&nbsp;线程服务器<br/>&nbsp;&nbsp;Apache<br/>&nbsp;&nbsp;Nginx<br/>&nbsp;&nbsp;http://blog.codingnow.com/2006/10/multi_process_design.html<br/><br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/%25E5%25A4%259A%25E8%25BF%259B%25E7%25A8%258B%25E6%259C%258D%25E5%258A%25A1%25E5%2599%25A8/" rel="tag">多进程服务器</a> , <a href="http://www.libing.net.cn/go.php/tags/%25E5%25A4%259A%25E7%25BA%25BF%25E7%25A8%258B%25E6%259C%258D%25E5%258A%25A1%25E5%2599%25A8/" rel="tag">多线程服务器</a> , <a href="http://www.libing.net.cn/go.php/tags/nginx/" rel="tag">nginx</a> , <a href="http://www.libing.net.cn/go.php/tags/iocp/" rel="tag">iocp</a> , <a href="http://www.libing.net.cn/go.php/tags/linux/" rel="tag">linux</a> , <a href="http://www.libing.net.cn/go.php/tags/kqueue/" rel="tag">kqueue</a> , <a href="http://www.libing.net.cn/go.php/tags/epoll/" rel="tag">epoll</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/read.php/2021.htm</link>
<title><![CDATA[MS-SQL 删除重复行]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[数据库]]></category>
<pubDate>Mon, 27 Apr 2009 08:54:51 +0000</pubDate> 
<guid>http://www.libing.net.cn/read.php/2021.htm</guid> 
<description>
<![CDATA[ 
	[codes=sql]<br/>delete&nbsp;&nbsp; Class_Tablessss<br/>&nbsp;&nbsp;from&nbsp;&nbsp; Class_Tablessss tt&nbsp;&nbsp; <br/>&nbsp;&nbsp;where&nbsp;&nbsp;&nbsp;&nbsp; exists(&nbsp;&nbsp; <br/>&nbsp;&nbsp;select&nbsp;&nbsp; 1&nbsp;&nbsp; <br/>&nbsp;&nbsp;from&nbsp;&nbsp; Class_Tablessss<br/>&nbsp;&nbsp;where&nbsp;&nbsp; StudentCard_No=tt.StudentCard_No&nbsp;&nbsp;<br/>&nbsp;&nbsp;and&nbsp;&nbsp; Class=tt.Class&nbsp;&nbsp; <br/>&nbsp;&nbsp;and&nbsp;&nbsp; id<tt.id)<br/>[/codes]<br/><br/>试试吧，这是针对我的数据库的，特殊的数据库可能需要特殊处理。尤其是字段方面。
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/MariaDB.php</link>
<title><![CDATA[MariaDB]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[数据库]]></category>
<pubDate>Sat, 25 Apr 2009 07:44:58 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/MariaDB.php</guid> 
<description>
<![CDATA[ 
	自从IBM收购Sun失败，Oracle以低0.1美金/每股的价格收购了Sun,又将引起什么？<br/><a href="http://monty-says.blogspot.com/" target="_blank">http://monty-says.blogspot.com/</a> 在他的博客提到他将精力转移到开发MYSQL的一个分支系统MariaDB中<br/><br/>具体参考 <a href="http://askmonty.org/wiki/index.php/Main_Page" target="_blank">Wiki MariaDB</a><br/><br/>个人希望该系统考虑进去更多的Cache,Cluster功能以及智能backup 等功能。<br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/mariadb/" rel="tag">mariadb</a> , <a href="http://www.libing.net.cn/go.php/tags/mysql/" rel="tag">mysql</a> , <a href="http://www.libing.net.cn/go.php/tags/sun/" rel="tag">sun</a> , <a href="http://www.libing.net.cn/go.php/tags/ibm/" rel="tag">ibm</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/read.php/2019.htm</link>
<title><![CDATA[杂七杂八的新信息]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[开发语言]]></category>
<pubDate>Sat, 25 Apr 2009 04:00:56 +0000</pubDate> 
<guid>http://www.libing.net.cn/read.php/2019.htm</guid> 
<description>
<![CDATA[ 
	1:GCC发布新版本，号称支持C++0x 参考 http://linuxtoy.org/archives/gcc-441-c-ox.html<br/>2:自从Oracle收购Sun后，MYSQL不知将何去何从，MYSQL创始人有意创造一分支，感觉这是好事情，开源的受益者是用户。而摒弃之前MYSQL的代码毕竟开发出更好的数据库系统<br/>3:Linux的前景应该很好，越来越多的投入其怀抱。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>BullionVault的后台服务器最初是运行Fedora Core Linux，现在换成了CentOS发行版，网络监控使用Nagios，系统镜像使用Drbd，工作计划使用Quartz，负载平衡使用Heartbeat，内容管理使用Subversion，其中BullionVault还向Nagios捐赠了加密补丁。网站搜索是Apache Lucene，网站内容管理是Drupal。前台桌面系统仍主要运行Windows，少量机器是Linux，邮件客户端是Thunderbird，浏览器是Firefox，办公软件是Microsoft Office（OpenOffice的电子表格程序常出现崩溃，所以出于可靠性的担忧而放弃使用）。<br/></div></div><br/><br/>以上来自solidot.info http://www.h-online.com/open/features/113118<br/><br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/gcc/" rel="tag">gcc</a> , <a href="http://www.libing.net.cn/go.php/tags/sun/" rel="tag">sun</a> , <a href="http://www.libing.net.cn/go.php/tags/oracle/" rel="tag">oracle</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/sina-ncache-nginx.php</link>
<title><![CDATA[sina根据nginx推的一个cache]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[服务器开发]]></category>
<pubDate>Thu, 23 Apr 2009 13:48:38 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/sina-ncache-nginx.php</guid> 
<description>
<![CDATA[ 
	http://code.google.com/p/ncache/<br/><br/>一个基于nginx的插件，在考虑一个大型文件系统时候，开发可以参考一下，相关连接<br/>http://code.google.com/p/ncache/wiki/HowToNcacheV2<br/><br/>不过感觉测试还不够多，不敢轻易使用。<br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/sina/" rel="tag">sina</a> , <a href="http://www.libing.net.cn/go.php/tags/ncache/" rel="tag">ncache</a> , <a href="http://www.libing.net.cn/go.php/tags/nginx/" rel="tag">nginx</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/cbuilder-libcurl-windows.php</link>
<title><![CDATA[C++Builder下libcurl的应用以及普通libcurl的应用方法]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[开发语言]]></category>
<pubDate>Thu, 23 Apr 2009 13:41:04 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/cbuilder-libcurl-windows.php</guid> 
<description>
<![CDATA[ 
	在Linux下开发BTTrackerServer的时候，曾经使用过该类，一直也没有怎么总结，这次是学生在开发的时候碰到，就根据网络资料进行整理了。申明，大部分资料来源于网络。<br/><br/>首先，使用libcurl的步骤如下：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>在基于LibCurl的程序里，主要采用callback function （回调函数）的形式完成传输任务，用户在启动传输前设置好各类参数和回调函数，当满足条件时libcurl将调用用户的回调函数实现特定功能。下面是利用libcurl完成传输任务的流程：<br/>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用curl_global_init()初始化libcurl<br/>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用 curl_easy_init()函数得到 easy interface型指针<br/>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用curl_easy_setopt设置传输选项<br/>4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 根据curl_easy_setopt设置的传输选项，实现回调函数以完成用户特定任务<br/>5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用curl_easy_perform（）函数完成传输任务<br/>6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 调用curl_easy_cleanup（）释放内存<br/>在整过过程中设置curl_easy_setopt()参数是最关键的，几乎所有的libcurl程序都要使用它。<br/></div></div><br/><br/>另外，在C++Builder中，方法使用的是LoadLibrary，GetProcAddress函数。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>下载最新的libcurl (win32-generic)<br/>取得 libcurl-4.dll. 复制到开发程序目录下面<br/>将include目录下的curl复制到BCB安装目录的include文件夹.<br/></div></div><br/>代码如下：<br/>[codes=c]<br/>#include <curl/curl.h><br/>#include <curl/easy.h><br/>#include <curl/types.h><br/> <br/>CURL* ( __stdcall *curl_easy_init )( );<br/>CURLcode ( __stdcall *curl_easy_setopt )( CURL *curl, CURLoption option, ...);<br/>CURLcode ( __stdcall *curl_easy_perform )(CURL *curl);<br/>void ( __stdcall *curl_easy_cleanup )(CURL *curl);<br/> <br/>void test()&#123;<br/>&nbsp;&nbsp;HMODULE cl = NULL;<br/>&nbsp;&nbsp;if( ( cl = LoadLibrary( "c:&#92;&#92;libcurl-4.dll" ) ) == NULL )&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox(NULL, "I can't load libcurl","ERROR", 0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;curl_easy_init =&nbsp;&nbsp;(CURL* ( __stdcall *)(&nbsp;&nbsp;) )GetProcAddress(cl, "curl_easy_init" );<br/>&nbsp;&nbsp;curl_easy_setopt =&nbsp;&nbsp;(CURLcode ( __stdcall *)(CURL *curl, CURLoption option, ...) )GetProcAddress(cl, "curl_easy_setopt" );<br/>&nbsp;&nbsp;curl_easy_perform =&nbsp;&nbsp;(CURLcode ( __stdcall *)(CURL *curl) )GetProcAddress(cl, "curl_easy_perform" );<br/>&nbsp;&nbsp;curl_easy_cleanup =&nbsp;&nbsp;(void ( __stdcall *)(CURL *curl) )GetProcAddress(cl, "curl_easy_cleanup" );<br/>&nbsp;&nbsp;CURL *curl;<br/>&nbsp;&nbsp;CURLcode res;<br/> <br/>&nbsp;&nbsp;curl = curl_easy_init();<br/>&nbsp;&nbsp;if(curl) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_easy_setopt(curl, CURLOPT_URL, "www.cs.ccu.edu.tw");<br/>&nbsp;&nbsp;&nbsp;&nbsp;res = curl_easy_perform(curl);<br/> <br/>&nbsp;&nbsp;&nbsp;&nbsp;/* always cleanup */<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_easy_cleanup(curl);<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;FreeLibrary(cl);<br/>&#125;<br/>[/codes]<br/><br/><br/>另外可执行代码如下：<br/>[codes=c]<br/>#include < stdio.h> <br/>#include " curl.h" <br/>//#pragma comment(lib, " ../curl-7.14.0/lib/libcurl_imp.lib" )<br/><br/>int main(void)<br/>&#123;<br/>&nbsp;&nbsp;CURL *&nbsp;&nbsp;curl = curl_easy_init(); <br/>&nbsp;&nbsp;&nbsp;&nbsp;if(curl) &#123;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CURLcode res;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//res = curl_easy_setopt(curl, CURLOPT_PROXY, " Test-pxy08:8080" ); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = curl_easy_setopt(curl, CURLOPT_URL, " http://www.vckbase.com" ); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = curl_easy_perform(curl); <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(CURLE_OK == res) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char *ct; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* ask for the content-type */<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, & ct); <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((CURLE_OK == res) & & ct)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(" We received Content-Type: %s " , ct); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125; <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* always cleanup */<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_easy_cleanup(curl); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125; <br/>&nbsp;&nbsp;&nbsp;&nbsp;return 0; <br/>&#125;<br/>[/codes]<br/><br/>参考文章：<br/>http://blog.csdn.net/collin1211/archive/2008/05/09/2422940.aspx<br/>http://blog.myspace.cn/e/402526981.htm<br/>http://hi.baidu.com/zkheartboy/blog/item/e40fc362f5d985dee6113ad9.html<br/>http://blog.chinaunix.net/u/12592/showart_1140684.html<br/>http://exodus.cs.ccu.edu.tw/~yuwen/NUBlog/<br/>http://blog.vckbase.com/michael/archive/2008/07/08/15426.html<br/><br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/c%252B%252Bbuilder/" rel="tag">c++builder</a> , <a href="http://www.libing.net.cn/go.php/tags/libcurl/" rel="tag">libcurl</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/centos-nginx-fastcgi.php</link>
<title><![CDATA[CentOS下面配置nginx以及php-fastcgi模式做web均衡]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[Linux]]></category>
<pubDate>Wed, 22 Apr 2009 11:51:17 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/centos-nginx-fastcgi.php</guid> 
<description>
<![CDATA[ 
	其实基本都是make && make install<br/>只是配置需要注意一下，参考了 回忆未来 张宴兄的文章<br/>http://blog.s135.com/post/366/<br/><br/>另外，熟悉了一下 imagemagick库和Imagick Image Library<br/><br/><br/>中代码摘录如下：<br/>[codes=php]<br/><?php&nbsp;&nbsp;<br/>header('Content-type: image/gif');&nbsp;&nbsp;<br/>&nbsp;&nbsp;<br/>$image = new Imagick('google_logo.gif');&nbsp;&nbsp;<br/>$image->adaptiveResizeImage(400,NULL);&nbsp;&nbsp;<br/>&nbsp;&nbsp;<br/>echo $image;&nbsp;&nbsp;<br/>?>&nbsp;&nbsp;<br/>[/codes]<br/><br/>其他详见帮助。<br/><br/>考虑大型图片服务器的假设可以采用该模式。<br/>使用rsync进行图片推送备份，加上memcache + mysql master/slave<br/>如果前端nginx压力过大，可以考虑采用lvs做一次均衡。<br/><br/>相关的参数如下：<br/><br/>[codes=c]<br/>http <br/>&#123;<br/>upstream myfastcgi &#123;<br/>&nbsp;&nbsp;server 192.168.10.110 weight=1;<br/>&nbsp;&nbsp;server 192.168.10.111 weight=1;<br/>&nbsp;&nbsp;server 192.168.10.112 weight=2;<br/>&#125;<br/><br/>location ~ &#92;.php$ &#123;<br/>&nbsp;&nbsp;fastcgi_pass myfastcgi;<br/>&nbsp;&nbsp;fastcgi_index index.php;<br/>&nbsp;&nbsp;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br/>&nbsp;&nbsp;include fastcgi_params;<br/>&#125;<br/>&#125;<br/>[/codes]<br/><br/>上面weight是权重。具体参考文档。<br/><br/>另外需要提到的是多台fast-cgi会导致session出现问题，参考文献六提出了解决方案。<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>项目背景基本上就是上面说的那些，下面大概说说相关的网络环境，然后进入具体的配置、实现过程：<br/>1、nginx服务器一台，IP地址：172.16.236.208<br/>2、php fastcgi服务器两台，IP分别为：172.16.236.210,172.16.236.211<br/>3、memcached服务器一台，IP为：172.16.236.220<br/>为了简化操作过程，上面的环境仅仅是达到项目需求的假设，实际项目中还有许多额外的处理。<br/>首先，修改nginx虚拟主机配置，将php的请求分发到各个php fastcgi服务器去，<br/>大致的配置过程可以参加我之前的文章：使用nginx配置多个php fastcgi负载均衡<br/>第二步，为php fastcgi服务器安装php-memcache扩展，参见：memcached、php-memcache安装笔记<br/>啰嗦一句，这一步其实只需在一台服务器上进行，其他php fastcgi的配置其实可以偷懒，就是将之前编译好的memcache.so拷贝到需要配置的服务器中，然后修改php.ini可以加载这个扩展即可。<br/>第三步，修改项目php源代码，使php的session存取使用memcached。<br/>之前没有认真去读php的手册，先是自己写session的handler，然后又碰到一些奇怪的问题。最后在php官方的memcache说明中找到了最简单的办法，其实只要在调用session_start()之前执行如下代码：<br/><br/>$host&nbsp;&nbsp;=&nbsp;&nbsp;'172.16.236.220'&nbsp;&nbsp; ;<br/>$port&nbsp;&nbsp;=&nbsp;&nbsp;'11211'&nbsp;&nbsp; ;<br/>$session_save_path = "tcp://$host:$port?persistent=1&weight=2&timeout=2&retry_interval=10,&nbsp;&nbsp;,tcp://$host:$port&nbsp;&nbsp;";<br/>ini_set('session.save_handler', 'memcache');<br/>ini_set('session.save_path', $session_save_path);<br/>其中$host是memcached服务器的ip地址，$port是memcached监听的端口。<br/>执行了如下代码以后，所有php fastcgi服务器的session操作都同步到了memcached服务器，而对于项目的php代码来说，以前该怎么用还是怎么用，完全可以不用像这篇博客开头那样，以为要改写php的session处理函数了。<br/><br/></div></div><br/><br/><br/>参考文章：<br/>http://www.imagemagick.org<br/>http://www.phpx.com/man/php-zh/ref.imagick.html<br/>http://hi.baidu.com/%D3%A9%BB%F0%B3%E6candy/blog/item/3efd1e803c3bbbd19123d9ea.html<br/>http://www.neatcn.com/show-274-1.shtml<br/>http://ipbfans.org/2009/02/nginx-php-fcgi-load-balance<br/>http://ipbfans.org/2009/02/memcached-php-session-load-balance<br/>Tags - <a href="http://www.libing.net.cn/go.php/tags/centos/" rel="tag">centos</a> , <a href="http://www.libing.net.cn/go.php/tags/nginx/" rel="tag">nginx</a> , <a href="http://www.libing.net.cn/go.php/tags/fastcgi/" rel="tag">fastcgi</a> , <a href="http://www.libing.net.cn/go.php/tags/rsync/" rel="tag">rsync</a> , <a href="http://www.libing.net.cn/go.php/tags/memcache/" rel="tag">memcache</a> , <a href="http://www.libing.net.cn/go.php/tags/mysql/" rel="tag">mysql</a> , <a href="http://www.libing.net.cn/go.php/tags/master/" rel="tag">master</a> , <a href="http://www.libing.net.cn/go.php/tags/slave/" rel="tag">slave</a> , <a href="http://www.libing.net.cn/go.php/tags/imagemagick/" rel="tag">imagemagick</a> , <a href="http://www.libing.net.cn/go.php/tags/imagick/" rel="tag">imagick</a>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/post/centos-vmware-vmware-tools.php</link>
<title><![CDATA[CentOS在VMWare下配置 VMWare Tools]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[Linux]]></category>
<pubDate>Tue, 21 Apr 2009 07:19:55 +0000</pubDate> 
<guid>http://www.libing.net.cn/post/centos-vmware-vmware-tools.php</guid> 
<description>
<![CDATA[ 
	通常的安装 都比较简单，点击安装之后，在系统中会弹出VMWare Tools光盘，然后只需要点击RPM安装即可，而CentOS下面，必须使用.gz安装。<br/><br/>具体可以参考文章：<br/><a href="http://www.cnblogs.com/oomusou/archive/2008/06/06/centos_vmware_tools.html" target="_blank">如何在CentOS安裝VMWare Tools? (OS) (Linux) (CentOS) (VMWare)</a><br/>
]]>
</description>
</item><item>
<link>http://www.libing.net.cn/read.php/2009.htm</link>
<title><![CDATA[J2ME Code tips[From books J2ME Game Development with MIDP2]]]></title> 
<author>huzhangyou2002 &lt;huzhangyou2002@gmail.com&gt;</author>
<category><![CDATA[多核]]></category>
<pubDate>Sun, 12 Apr 2009 11:01:47 +0000</pubDate> 
<guid>http://www.libing.net.cn/read.php/2009.htm</guid> 
<description>
<![CDATA[ 
	1. Use StringBuffer instead of String because of the fact the String object can not<br/>be changed. Any modification to a String variable is actually a new object<br/>creation.<br/>2. Accessing class variables directly is faster then using setter and getter<br/>methods<br/>3. Using local variables are more efficient then instance/class variables<br/>4. Using variables are more efficient then arrays.<br/>5. Avoid synchronization in loops because there is an extra over head to lock and<br/>unlock each time the loop occurs<br/>6. Counting down in loops is faster then counting up<br/>7. Use compound operators like x += 1 instead o f x = x + 1 because fewer byte<br/>codes is generated<br/>8. Remove constant calculations in loops<br/>9. Reuse objects<br/>10. Assign null to unused objects, especially unused threads<br/>11. Try to use already built in methods, for example if you want to copy data from<br/>one array to another use System.arraycopy more then likely this method will<br/>be more efficient then the one you created yourself
]]>
</description>
</item>
</channel>
</rss>
