PHP’s Forecast: Partly Cloudy

Posted on 24th June 2009 by Nio in 程序人生 - Tags: ,

PHP’s Forecast: Partly Cloudy

There are three kinds of services that are commonly associated with the cloud: Software as a Service (SaaS), Platform as a Service (PaaS) and Infrastructure as a Service (IaaS). Software as a Service has gotten a lot of good press in the past few years, as Salesforce and the like have seen adoption from the smallest shops to the largest corporations. Beyond a few web service API’s, however, SaaS doesn’t offer much for application developers. Platform as a Service, on the other hand, provides full-service hosting environments that can automatically allocate resources as your applications need them. Google App Engine, for example, supports sandboxed Python and Java environments (PHP is the most requested feature, and hasn’t been ruled out by the GAE team). PaaS environments often extend a SaaS offering, as is the case with SugarCRM’s certified modules. But PaaS has some big shortcomings: your applications are far from portable and are limited to what the vendors specifically permit them to do. Infrastructure as a Service is less confining. Your applications can use these services to scale with the same hardware that backs the largest sites on the web. You can usually install the OS of your choice and run your applications in environments tailored to their needs. The tradeoff is that you have to provision additional resources manually to handle spikes in load, and you must design your applications differently if you’d like to use the services that improve the scalability of your app. As we’ll see later, changing your mindset to take advantage of these services isn’t necessarily a bad thing…

父亲节礼物

Posted on 13th June 2009 by Nio in 日常生活 - Tags:

我的第一个父亲节礼物竟然是魔方,而且是很怪异的魔方。Shxll 刚买回来的时候,我一看都呆了,呵呵。如果光是形状上的变化,是没什么难度的,和普通的三阶魔方没什么区别,但所有面的颜色都一样,就有些难度了,因为只能靠抽象想像记忆哪一块在哪个位置上。今天早上,总算玩出来了,看来我的抽象想像能力还不错,嘻嘻 :D


魔方完成后的模样。


魔方乱七八糟的样子,很像变形金刚。

PHP 通过 Tor 代理实现多 IP 访问

Posted on 8th June 2009 by Nio in 程序人生 - Tags: , , ,

经常需要使用 PHP 写脚本来模拟浏览器对一些页面进行访问,但客户端 IP 却是个问题,所以考虑通过走代理的方式。Tor 无疑是一个很好的选择。通过 curl 相关函数,很容易就可以实现通过 tor 进行访问。


<?php
function tor($url)
{
    $ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
    $op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
    $agent  $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
    // Tor 地址与端口
    $tor '127.0.0.1:9050';
    // 连接超时设置
    $timeout 300;
    $ack curl_init();
    curl_setopt($ackCURLOPT_PROXY$tor);
    curl_setopt($ackCURLOPT_URL$url);
    curl_setopt($ackCURLOPT_HEADER0);
    curl_setopt($ackCURLOPT_USERAGENT$agent);
    curl_setopt($ackCURLOPT_RETURNTRANSFER1);
    curl_setopt($ackCURLOPT_FOLLOWLOCATION1);
    curl_setopt($ackCURLOPT_TIMEOUT$timeout);
    curl_setopt($ackCURLOPT_PROXYTYPECURLPROXY_SOCKS5);
    $result curl_exec($ack);
    curl_close($ack);
    return $result;
}
?>