多IP应用

可以加一条指定源地址的路由来试试:
假定 指定使用1.1.1.2地址, 其所在的子接口为eth1:0 则
route add <目标网段/主机> gw <网关> dev eth1:0

如果是多网卡绑同网段ip也一样, 将dev后面的eth1:0换成 eth1 (假定1.1.1.2绑在eth1网卡上).

No Comments

企业先锋

我和diane的合影,臭美一下

No Comments

运用header 让php程序被浏览器缓存

if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (time()-strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < 3600*24)) {
     header(“HTTP/1.1 304 Not Modified”);
     exit;
   }
   header(“Last-Modified: ” . gmdate(‘D, d M Y H:i:s \G\M\T’, time()) );

expires:不大好用,直接敲还是会访问,这个虽然占服务器连接,但是至少他304,后面的不执行了。

2 Comments

过滤掉array中的空字串 php函数

array_filter(array(’2356′,”,’235′,’677′), ‘strlen’);

空会被过滤,剩下2356 235和677

No Comments

php 函数处理相对目录和绝对目录混合目录

function getAbsolutePath($path) {
        $path = str_replace(array(‘/’, ‘\\’), DIRECTORY_SEPARATOR, $path);
        $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), ‘strlen’); //过滤掉空。。
        $absolutes = array();
        foreach ($parts as $part) {
            if (‘.’ == $part) continue;
            if (‘..’ == $part) {
                array_pop($absolutes);
            } else {
                $absolutes[] = $part;
            }
        }
        return DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $absolutes);
}

No Comments

php打开报错

error_reporting(E_ALL);
ini_set(“display_errors”, 1);

No Comments

linux服务器查看cpu 内存相关信息

转帖:

测试机器的硬件信息:

查看CPU信息(型号)
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
      8  Intel(R) Xeon(R) CPU            E5410   @ 2.33GHz
(看到有8个逻辑CPU, 也知道了CPU型号)
Read the rest of this entry »

No Comments

php 直读post主体数据

A quick tip for reading raw http POST data in PHP. For example if we have a xml posted to a page, we can read the raw data with the following code.

$xml = file_get_contents('php://input');

We could use $HTTP_RAW_POST_DATA instead, but many times it does not work due to some php.ini settings. Note that ‘php://input’ does not work with enctype=”multipart/form-data”.

No Comments

php oci8 oracle连接池(11g) drcp

一个关于drcp的文档http://www.docin.com/p-5599651.html

使用 Oracle 数据库 11g 连接池

Oracle 数据库 11g 包含一个专门针对需要高可扩展性的应用程序的新特性:数据库驻留连接池 (DRCP)。通过 DRCP,我们可以在不同应用程序进程间共享数据库连接,从而更高效地使用服务器资源并全面提升吞吐量。Zend Server 随附的 PHP OCI8 扩展(目前为 V1.3.5)包含对 DRCP 的即用支持,使开发人员可以立即在其 PHP 应用程序中使用该特性。有关 PHP 和 DRCP 的更多详细信息,请参阅此处

要在 Oracle 中启用 DRCP,登录到数据库服务器并启动连接池: 

shell> sqlplus / as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on Tue May 26 14:24:13 2009
Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Release 11.1.0.6.0 - Production

SQL> execute dbms_connection_pool.start_pool();
PL/SQL procedure successfully completed.

通过查询特定的 DBA_CPOOL_INFO 视图确认该池已启动:

SQL> SELECT CONNECTION_POOL, STATUS, MAXSIZE
  2  FROM DBA_CPOOL_INFO;

CONNECTION_POOL             STATUS		    MAXSIZE
----------------------------------------------------------
SYS_DEFAULT_CONNECTION_POOL ACTIVE		    40

然后,在 Zend Server 管理控制台的 Server Setup → Directives 页面,找到 OCI8 部分并在 oci8.connection_class 变量中设置 PHP 应用程序所使用的 DRCP 连接类的名称。该用户选择的名称允许不同应用程序的池化服务器间的逻辑划分:图 17 

最后,通过向您的 oci_connect() 连接字符串中添加关键字 POOLED 使您的 PHP 应用程序使用 DRCP。虽然不是必需的,但要实现最大可扩展性,我们推荐您用 oci_pconnect() 函数替换 oci_connect() 函数。修改为使用 DRCP (drcp.php) 之前的示例如下:

<html>
  <head>
    <style type="text/css">
    table { border-collapse: collapse; }
    td { border: solid 1px black; padding: 3px; }
    </style>
  </head>
  <body>
  <h2>Cities</h2>
  <?php
  // open database connection
  $db = oci_pconnect('john', 'doe', '//achilles/orcl:POOLED');
  if (!$db) {
    trigger_error('Unable to connect to database', E_USER_ERROR);
  }

  // formulate and parse query
  $sql = 'SELECT * FROM CITIES';
  $stmt = oci_parse($db, $sql);

  // execute query
  oci_execute($stmt);

  // iterate over result set
  $count = 0;
  echo '<table>';
  while ($row = oci_fetch_object($stmt)) {
    echo '<tr>';
    echo '<td>' . $row→CITY_ID . '</td>';
    echo '<td>' . $row→CITY_NAME . '</td>';
    echo '</tr>';
    $count++;
  }
  echo '</table><br/>';
  echo $count . ' record(s) found.';  

  // close connection
  oci_free_statement($stmt);
  oci_close($db);
  ?>
  </body>
</html>

唯一的更改是连接调用。无需更改应用程序。您还可以指定服务器连接通过 $ORACLE_HOME/network/admin/tnsnames.ora 文件进行汇集,如以下示例所示: 

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = achilles)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = POOLED)
      (SERVICE_NAME = orcl)
    )
  )

您的连接调用将如下所示:

 $db = oci_pconnect('john', 'doe', 'ORCL');

注意,DRCP 不能在尚无 Oracle 11g 库的 Mac OS X 中使用,而且在任何情况下,Zend Server 的商业版在 Mac OS X 上都不受支持。

No Comments

ratproxy 可以监控所有的xss跨站攻击,并给出详细的测试报告和危险等级

http://code.google.com/p/ratproxy/

tar -zxvf 了那个包

No Comments

自己写的jsonServer jsonClient

  1. <?php
  2. /**
  3.  * 调用TEA加密算法,对所有Service目录下的类,都实例化之后调用。
  4.  * @author 肖江
  5.  * @filesource  service/0
  6.  * @classname Json Server调用
  7.  * @copyright 2010-2-4
  8.  */
  9. class SjsonServer {
  10.  static $jsonDecode; //jsonDecode类
  11.  static $serverInfo=array(); //解密段密码
  12.  static $domain; //域名
  13.  static $myClass; //要执行的className
  14.  function __construct() {
  15.   self::$jsonDecode=new Btea();
  16.  }
  17.  function setKeyPasswd($domain) {
  18.   self::$serverInfo[‘keyPasswd’]=l(‘FmyRpc’)->$domain;
  19.   self::$domain=$domain;
  20.  }
  21.  /**
  22.   * 设置class 供外部使用
  23.   * @author 肖江
  24.   * @param $class
  25.   * @return unknown_type
  26.   */
  27.  function setClass($class) {
  28.   self::$myClass=$class;
  29.   return $this;
  30.  }
  31.  /**
  32.   * 主函数,由index调用。
  33.   * @author 肖江
  34.   * @param $className
  35.   * @return unknown_type
  36.   */
  37.  function run($className) {
  38.   try {
  39.   $this->setClass($className);
  40.   $this->parseData($_REQUEST);
  41.   $GLOBALS[‘domain’]=self::$domain;
  42.   $classObject=new $className; //load
  43.   $param=isset($_REQUEST[‘Data’])?json_decode($_REQUEST[‘Data’],true):;
  44.   if(!is_array($param)) $param=array();
  45.   <a href="mailto:$result=@call_user_func_array(array($classObject,self::$serverInfo['method'">$result=@call_user_func_array(array($classObject,self::$serverInfo['method'</a>]), $param);
  46. //  $debug=new BdebugE();
  47. //  $debug->showErr('JsonServer 执行了.',$className."\r\n结果:\r\n".print_r($result,true),1);
  48.   echo json_encode(array('Return'=>$result)); //输出执行结果
  49.   } catch (dherror $err) {
  50.    echo json_encode(array('Error'=>$err->getMessage()))//忽略showMode 因为json 服务器不能用debugE,errCode也无法让client对照。
  51.   }
  52.  }
  53.  /**
  54.   * 检查Data
  55.   * @author 肖江
  56.   * @param $data
  57.   * @return unknown_type
  58.   */
  59.  function parseData($data) {
  60.   if(!isset($data['Domain'])) $this->error('未找到预先定义的domain字段',10055);
  61.   else $this->setKeyPasswd($data['Domain']);
  62.   if(!isset($data['Method'])) $this->error('未找到预先定义的method字段',10056);
  63.   else {
  64.    if(!isset($data['SecureData'])) $this->error('未找到预先定义的SecureData字段',10061);
  65.    else self::$serverInfo['method']=$this->getMethod($data['Method'],$data['SecureData']);
  66.   }
  67.  }
  68.  /**
  69.   * 获取方法名
  70.   * @author 肖江
  71.   * @param $methodStr
  72.   * @return unknown_type
  73.   */
  74.  function getMethod($methodStr,$secureCode) {
  75.   //$method=self::$jsonDecode->decrypt($methodStr,self::$serverInfo['keyPasswd']);
  76.   if(md5($methodStr.‘|’.self::$serverInfo[‘keyPasswd’])!=$secureCode)
  77.    $this->error(‘数据校验不通过’,10060);
  78.   $method=explode(‘.’,$methodStr);
  79.   if((time()-$method[0])>3600) $this->error(‘过期协议’,10057);
  80.   if(!isset($method[1])) $this->error(‘method定义出错’,10058);
  81.   return $method[1];
  82.  }
  83.  /**
  84.   * 错误抛出
  85.   * @author 肖江
  86.   * @param $errStr
  87.   * @param $errCode
  88.   * @param $className
  89.   * @return unknown_type
  90.   */
  91.  function error($errStr,$errCode) {
  92.   throw new dhError ( $errStr,$errCode,‘接口 :’.self::$myClass,1 );
  93.  }
  94. }
  1.  
  2. <?php
  3. /**
  4.  *
  5.  * @author 肖江
  6.  * @test
  7.  */
  8. class SjsonClient {
  9.  static $baseInfo=array(); //基础信息
  10.  static $jsonDecode; //加密解密模块
  11.  static $curl; //请求类
  12.  /**
  13.   * 构造函数
  14.   * @author 肖江
  15.   * @param $url
  16.   * @param $domain
  17.   * @return unknown_type
  18.   */
  19.  function __construct($url,$domain) {
  20.   self::$jsonDecode=new Btea();
  21.   self::$curl=new Bcurl();
  22.   self::$baseInfo[‘url’]=$url;
  23.   self::$baseInfo[‘domain’]=$domain;
  24.   self::$baseInfo[‘keyPasswd’]=l(‘FmyRpc’)->$domain;
  25.   self::setArrMode();
  26.   if(strlen(self::$baseInfo[‘keyPasswd’])<1)
  27.    $this->error(‘未能找到相关网站密码’,10035,$url);
  28.  }
  29.  /**
  30.   * 设置client返回的是obj还是array
  31.   * @author 肖江
  32.   * @param boolean true是array false是object
  33.   * @return unknown_type
  34.   */
  35.  static function setArrMode($mode=true) {
  36.   self::$baseInfo[‘arrMode’]=$mode;
  37.   return $this
  38.  }
  39.  /**
  40.   * 内部函数
  41.   * @param string 函数名
  42.   * @param array 参数
  43.   */
  44.  function __call($funcName,$param) {
  45.   try {
  46.    $callRequest=$this->makeCall($funcName,$param);
  47.  
  48.    $result=self::$curl->init(array(‘url’ => self::$baseInfo[‘url’],
  49.                  ‘method’=>‘POST’,
  50.            ‘post_fields’=>$callRequest
  51.    ))->exec();
  52.           if(isset($result[‘body’])) return  json_decode($result[‘body’],self::$baseInfo[‘arrMode’]);
  53.   } catch (dhError $e) {
  54.    $e->showDebugE(); //处理showMode=1
  55.    $e->getMsg(); //处理showMode=0/2
  56.   }
  57.  }
  58.     /**
  59.   * 创建一次请求信息
  60.   * @author 肖江
  61.   * @param $funcName
  62.   * @param $param
  63.   * @return unknown_type
  64.   */
  65.  function makeCall($funcName,$param) {
  66.   $callRequest=array();
  67.   $callRequest[‘Domain’]=self::$baseInfo[‘domain’];
  68.   $callRequest[‘Method’]=time().‘.’.$funcName;
  69.   $callRequest[‘SecureData’]=md5($callRequest[‘Method’].‘|’.self::$baseInfo[‘keyPasswd’]);
  70.   $callRequest[‘Data’]=json_encode($param);
  71.   return $callRequest;
  72.  }
  73.  /**
  74.   * 错误抛出
  75.   * @author 肖江
  76.   * @param $errStr
  77.   * @param $errCode
  78.   * @param $className
  79.   * @return unknown_type
  80.   */
  81.  function error($errStr,$errCode,$className) {
  82.   throw new dhError ( $errStr,$errCode,$className,1 );
  83.  }
  84. }
  85.  

No Comments

php oci8 connect自动转码

$conn = oci_connect(‘hr’, ‘welcome’, ‘localhost/XE’, ‘AL32UTF8′);
如果oracle是gbk的,这条语句会让所有utf8的数据进入的时候自动转码成gbk的,读出的时候自动转码成utf8的,相当智能!

No Comments

java和php能共享的session(通过memcache)

用普通的memcache重写session 实际上是为了让session用json格式保存,好用java读取..

java只需要修改它的session程序,就可以做到java php session通用(相互无缝调取)了

不过要注意$id就是session_id是在php.ini中设置name 要和java统一。。否则还是没戏

Read the rest of this entry »

No Comments

nginx ip 传递给apache remote_add..

http://stderr.net/apache/rpaf/download/

编译吗。。用这个

Read the rest of this entry »

No Comments

serialize print_r json_encode比较

好吧,我承认我只是为了了解一下这3个函数的效率如何
Read the rest of this entry »

No Comments

apache cassandra在php上的一些应用

http://github.com/mjpearson/Pandra/downloads

Dependencies

        * Cassandra >= 0.6

        * Thrift Interface (tested cassandra.thrift and pre-generated files are packaged)

        * PHP >= 5.3

        * OSSP PHP-UUID module

        – Optional

            * Model Generation – syck yaml

            * Caching – APC or Memcached (PECL)

            * Logging – Syslog, Sendmail and FirePHP
http://incubator.apache.org/cassandra/

No Comments

一个谈技术架构的blog还不错

http://timyang.net/

一个key value的ppt挺好的

http://www.slideshare.net/iso1600/key-value-store

No Comments

GraphicsMagick 安装使用

淘宝用于图片resize和水印的工具不是imagemagick而是graphicsmagick,效率据说高一些,我们来试试

download : http://www.graphicsmagick.org/download.html

下载.tar.gz文件 Read the rest of this entry »

No Comments

apache rewrite RewriteCond 写法

看别的没用,就这个最好。。

http://www.uplinux.com/download/doc/apache/ApacheManual/misc/rewriteguide.html

No Comments

让apache支持shtml 文件(转)

介绍一下shtml和shtm

关于shtml,shtml是一种基于SSI技术的文件,也就是Server Side Include–SSI 服务器端包含指令,一些Web Server如果有SSI功能的话就会对shtml文件特殊招待,服务器会先扫一次shtml文件看没有特殊的SSI指令存在,如果有的话就按Web Server设定规则解释SSI指令,解释完后跟一般html一起调去客户端。

关于shtm,shtm与shtml的关系和htm与html的关系大致相似,这里就不多说了。

html或htm与shtml或shtm的关系是什么

html或者htm是一种静态的页面格式,也就是说不需要服务器解析其中的脚本,或者说里面没有服务器端执行的脚本,而shtml或者shtm 由于它基于SSI技术,当有服务器端可执行脚本时被当作一种动态编程语言来看待,就如asp、jsp或者php一样。当shtml或者shtm中不包含服务器端可执行脚本时其作用和html或者htm是一样的。

如何使你的Apache服务器支持SSI?

Apache默认是不支持SSI的,需要我们更改httpd.conf来进行配置。我这里以windows平台的Apache 2.0.x为例,打开conf目录下的httpd.conf文件,搜索“AddType text/html .shtml”,搜索结果:
# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml
把这两行前面的#去掉。
然后搜索“Options Indexes FollowSymLinks”
在搜索到的那一行后面添加“ Includes”
即将该行改变为 Options Indexes FollowSymLinks Includes
保存httpd.conf,重起apache即可。

到此我们就完成了对Apache SSI的设置 

No Comments