海运的博客

NoSQL持久化存储之Berkeley DB

发布时间:January 2, 2014 // 分类:NoSQL // No Comments

安装Berkeley DB:

wget http://download.oracle.com/berkeley-db/db-6.0.20.tar.gz
tar zxvf db-6.0.20.tar.gz 
cd db-6.0.20/build_unix/
../dist/configure --prefix=/usr/local/berkeleydb --enable-cxx
make && make install

安装PHP扩展:

cd ../lang/php_db4/
phpize
./configure --with-db4=/usr/local/berkeleydb/
make && make install
echo 'extension=db4.so' >> /etc/php.ini

简单使用:

<?php
   $db = new Db4();
   $db->open(null, "/var/tmp/db4", "test"); 
   $db->put('key', 'value');
   $db->get('key');
?>

http://www.oracle.com/technetwork/products/berkeleydb/downloads/index-082944.html

PHP函数pfsockopen建立Keep-Alive连接

发布时间:January 1, 2014 // 分类:PHP // No Comments

使用Keep-Alive可减少建立TCP连接的开销,pfsockopen在脚本执行期间可重用socket实现Keep-Alive。

<?php
   function httpget($host)   
   {   
      $conn = pfsockopen($host,80,$errno, $errstr, 30);   
      if (!$conn)    
      {   
         echo "$errstr ($errno)<br />\n";   
         return;   
      }   

      $header = "HEAD / HTTP/1.1\r\n";   
      $header.= "Host: {$host}\r\n";   
      $header.= "Connection: Keep-Alive\r\n\r\n";    

      fwrite($conn,$header);   

      /*
      while (!feof($conn)) {   
         $resp .= fgets($conn);   
      }
      */

      //fclose($conn); //关闭连接后再连接keepalive失效
      return $resp;   
   }   
   $host = 'www.haiyun.me';   
   $count = 2;   

   for ($i = 0; $i < $count; $i++) {   
      echo httpget($host);
      sleep(10);
   }   
?>

Tcpdump分析,1-3行第一次建立TCP连接,第8行建立第二次连接跳过TCP三次握手。

20:27:17.016435 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [S], seq 2231661196, win 5840, options [mss 1400,sackOK,TS val 9961058 ecr 0,nop,wscale 6], length 0
20:27:17.016531 IP 162.211.225.71.80 > 1.2.3.4.49022: Flags [S.], seq 2734092091, ack 2231661197, win 14480, options [mss 1460,sackOK,TS val 1880475065 ecr 9961058,nop,wscale 7], length 0
20:27:17.342653 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [.], ack 1, win 92, options [nop,nop,TS val 9961139 ecr 1880475065], length 0
20:27:17.345695 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [P.], seq 1:65, ack 1, win 92, options [nop,nop,TS val 9961139 ecr 1880475065], length 64
20:27:17.345716 IP 162.211.225.71.80 > 1.2.3.4.49022: Flags [.], ack 65, win 114, options [nop,nop,TS val 1880475394 ecr 9961139], length 0
20:27:17.876911 IP 162.211.225.71.80 > 1.2.3.4.49022: Flags [P.], seq 1:427, ack 65, win 114, options [nop,nop,TS val 1880475925 ecr 9961139], length 426
20:27:18.202503 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [.], ack 427, win 108, options [nop,nop,TS val 9961355 ecr 1880475925], length 0
20:27:27.346477 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [P.], seq 65:129, ack 427, win 108, options [nop,nop,TS val 9963640 ecr 1880475925], length 64
20:27:27.346508 IP 162.211.225.71.80 > 1.2.3.4.49022: Flags [.], ack 129, win 114, options [nop,nop,TS val 1880485395 ecr 9963640], length 0
20:27:27.838571 IP 162.211.225.71.80 > 1.2.3.4.49022: Flags [P.], seq 427:853, ack 129, win 114, options [nop,nop,TS val 1880485887 ecr 9963640], length 426
20:27:28.165367 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [.], ack 853, win 125, options [nop,nop,TS val 9963845 ecr 1880485887], length 0
20:27:37.346030 IP 1.2.3.4.49022 > 162.211.225.71.80: Flags [R.], seq 129, ack 853, win 125, options [nop,nop,TS val 9966140 ecr 1880485887], length 0
分类
最新文章
最近回复
  • xiongrui: 看图
  • 傻狍子: filebrowser好像和这功能一样? https://github.com/filebro...
  • 陶国文: 想看看能不能安装
  • 傻狍子: 服务端设置了用户名密码认证的话,在openwrt的openvpn客户端的配置文件当中该如何更改...
  • 王阴阳师: 感谢,一点不啰嗦,还很管用!
  • simon: 刚刚看了我的vps,玛德,居然也有人在一直尝试登录,幸好我的密码是强密码
  • thornbird: 又学会一招,不错
  • 头很黑: 除了发送eth转账 ,还能转账其他的代币吗 比如eos
  • 米扑博客: 总结的很棒
  • 米扑博客: 很赞的博客