对于包含的中文的URL可以这样处理
Decode
NSString * str = [strURLstringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Encode
- (NSString*)encodeURL:(NSString *)string
{
NSString *newString = NSMakeCollectable([(NSString *)CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef)string, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"),
CFStringConvertNSStringEncodingToEncoding([self stringEncoding])) autorelease]);
if (newString) {
return newString;
}
return @"";
}
网赚项目之站群
第二课 做站群之前的准备工作
上节课我们介绍了什么是站群,如何利用站群赚钱,以及站群的发展趋势,我们明白,利用站群是肯定可以赚到钱的。这节课我们主要介绍如何动手做站群,以及做个站群需要花费多少钱。
1、 做站群需要准备什么?
不论是做一个站还是做个站群,我们都需要准备:1、域名 2、网站空间 3、网站程序。所谓域名就是网站的名字,如www.baidu.com,这就是域名;空间就是你的程序放置的地方,和我们电脑中的硬盘一样;程序就是用什么做网站,你可以自己做,也可以用一些已经做好的程序,如做博客用zblog,做论坛用disuz,如果只是文章类的网站,就可以选cms系统,如帝国cms。
2、做站群需要花费多少钱?
这里我们先看看做个站群需要花费多少钱,这毕竟是大家最为关心的。我们上淘宝网看看一个域名和空间的价格。域名有30-100元的不等,我们选个40元的,这个不分价格多少,都是可以用的,价格不同是因为代理商的不同。空间价格从30-3000元的都有,我们选个60元的,毕竟是做站群嘛,没必要选贵的,特别是新手,可以先练习练习。这样,如果做100个站的话,域名与空间的费用就是(40+60)*100=1万元。昨天我们已经算过了站群的盈利能力,按照每个站10元/天的话,100个站一月也是可以收入3万元的,所以这个投入是不多的。这是我们做站群的第一套方案,花费1万元。
如果上面的方案感觉有点贵的话,我们还有办法,域名用info的,在淘宝上搜一下,每个5-30元的都有,我们选个10元的;空间用vps,
或者直接在淘宝上搜站群,就有很多专门提供站群服务的服务器,选个3000元一年的就行。这样子不到5000元,一个站群就搞定了。当然效果嘛,自己测试,因为我自己用的是第一套方案。这是第二套方案,花费不到5000元。
第三套方案:免费空间和域名。百度一下,这样的空间和域名很多。如果你是新手想测试下站群,用免费产品就可以,但如何你想利用站群赚钱的话,免费空间和域名就不i行了,因为百度和google不收录免费的产品。
有投入才有回报嘛,我建议大家用第一套方案。
3、哪里购买域名和空间?
这里我给大家介绍几个买域名和空间的地方,都是信誉站点,本人就在这里买的很多域名和空间。
1、国内比较有名的域名注册商:
新网互联 网址:http://www.dns.com.cn/
新网数码 网址:http://www.xinnet.com/
中国万网 网址:http://www.net.cn
35互联 网址:http://www.35.com/
中资源 网址:http://www.zzy.cn/
godaddy 网址:http://www.godaddy.com/
易名中国 网址:http://www.ename.net
金名网 网址:http://www.4.cn/
2、国外比较有名的域名注册商
1、Godaddy 网址:http://www.godaddy.com/
2、name 网址:http://www.name.com/
3、enom 网址:www.enom.com
4、Ipower 网址:www.ipower.com
3、推荐购买域名空间地方
淘宝网:http://www.taobao.com/
景安网络:http://www.zzidc.com/
中电云集:http://www.chinaccnet.com/
炎黄网络:
1、网站程序选择
博客程序有:zblog wordpress
Cms系统:帝国cms 动易cms
淘宝客程序:淘客帝国 织梦 多多返利网
建议大家最好不要购买源码程序,因为源码程序里面经常有漏洞程序,而且没有更新。
提升Tomcat性能方法有很多种,使用NIO Connector和启用gzip压缩是其中两种。
NIO:Java New IO,使用了多路复用的技术,无疑要比普通的IO socket要高效。
gzip:对需要传输到前台的内容首先在内存中进行gzip压缩,这样可以大大的减少网络带宽占用。前提是前台的Accept-Encoding允许gzip。
但是,当同时配置了这两个时,会发现大于48KB的文件并没有进行压缩。
经查Tomcat源码,发现org.apache.catalina.servlets.DefaultServlet中:
/**
* Check if sendfile can be used.
*/
protected boolean checkSendfile(HttpServletRequest request,
HttpServletResponse response,
CacheEntry entry,
long length, Range range) {
if ((sendfileSize > 0)
&& (entry.resource != null)
&& ((length > sendfileSize) || (entry.resource.getContent() == null))
&& (entry.attributes.getCanonicalPath() != null)
&& (Boolean.TRUE == request.getAttribute("org.apache.tomcat.sendfile.support"))
&& (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
&& (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))) {
request.setAttribute("org.apache.tomcat.sendfile.filename", entry.attributes.getCanonicalPath());
if (range == null) {
request.setAttribute("org.apache.tomcat.sendfile.start", new Long(0L));
request.setAttribute("org.apache.tomcat.sendfile.end", new Long(length));
} else {
request.setAttribute("org.apache.tomcat.sendfile.start", new Long(range.start));
request.setAttribute("org.apache.tomcat.sendfile.end", new Long(range.end + 1));
}
return true;
} else {
return false;
}
}此处的sendfileSize = 48*1024,默认值为48KB,可以发现,当文件大小大于48KB时,Tomcat并未马上将内容写回到output中,而是把文件的路径记录下来。
/**
* Serve the specified resource, optionally including the data content.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param content Should the content be included?
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
protected void serveResource(HttpServletRequest request,
HttpServletResponse response,
boolean content)
throws IOException, ServletException {
......
// Copy the input stream to our output stream (if requested)
if (content) {
try {
response.setBufferSize(output);
} catch (IllegalStateException e) {
// Silent catch
}
if (ostream != null) {
if (!checkSendfile(request, response, cacheEntry, contentLength, null))
copy(cacheEntry, renderResult, ostream);
} else {
copy(cacheEntry, renderResult, writer);
}
}
......
}并在Http11Processor的process方法的最后一部分,把文件内容以FileChannel的形式写回到前台,不需要先把文件内容先读到用户内存->压缩->写回socket内核内存。
/**
* Process pipelined HTTP requests using the specified input and output
* streams.
*
* @throws IOException error during an I/O operation
*/
public SocketState process(NioChannel socket)
throws IOException {
......
// Do sendfile as needed: add socket to sendfile and end
if (sendfileData != null && !error) {
KeyAttachment ka = (KeyAttachment)socket.getAttachment(false);
ka.setSendfileData(sendfileData);
sendfileData.keepAlive = keepAlive;
SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
//do the first write on this thread, might as well
openSocket = socket.getPoller().processSendfile(key,ka,true,true);
break;
}
......
}这种NIO底层读写channel的形式避免了读取到用户内存的开销,也可以提升性能。
目前,尚不清楚使用NIO快,还是gzip较快,有待测试。
如果在使用NIO的同时还一定要用gzip,可以关闭NIO Connector的useSendFile选项。
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443"
useSendfile="false"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/javascript" />参考:http://tomcat.apache.org/tomcat-6.0-doc/config/http.html