海运的博客

UDP端口转发

发布时间:April 30, 2014 // 分类:网络工具 // No Comments

使用SOCAT:

socat UDP4-LISTEN:53,fork UDP4:162.211.225.71:53

使用IPTABLES DNAT:http://www.haiyun.me/archives/iptables-dnat-public-ip.html

OpenWRT安装PHP环境

发布时间:April 29, 2014 // 分类:OpenWrt // No Comments

由于空间有限,仅安装PHP-CGI,占用空间2.2M左右。

opkg update
opkg install php5-cgi

配置uhttpd支持PHP:

/etc/config/uhttpd 
config uhttpd php
list listen_http 0.0.0.0:8080
option home /home/wwwroot
option index_page index.php
list interpreter ".php=/usr/bin/php-cgi"

Firefox下Imacros使用XMLhttprequest获取数据

发布时间:April 29, 2014 // 分类:JS // No Comments

function HTTPGET(url) {
  var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest);
  async = false;
  request.open('GET', url, async);
  request.send();
  if (request.status !== 200) {
    var message = 'an error occurred at url: ' + url + ', status: ' + request.status;
    return message;
  }
  return request.response;
}

HTTPGET('http://www.haiyun.me');

JS生成随机数字/字符

发布时间:April 29, 2014 // 分类:JS // No Comments

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
var num = getRandomInt(5, 8)

function getrRandomStr(len) {
  var text = " ";
  var charset = "abcdefghijklmnopqrstuvwxyz";

  for (var i = 0; i < len; i++)
    text += charset.charAt(Math.floor(Math.random() * charset.length));

  return text;
}
getrRandomStr(num);

PHP多进程Class类

发布时间:April 26, 2014 // 分类:PHP // No Comments

<?php
   declare(ticks=1);
   //A very basic job daemon that you can extend to your needs.
   class JobDaemon{

      public $maxProcesses = 8;
      protected $jobsStarted = 0;
      protected $currentJobs = array();
      protected $signalQueue=array();  
      protected $parentPID;

      public function __construct(){
         echo "constructed \n";
         $this->parentPID = getmypid();
         pcntl_signal(SIGCHLD, array($this, "childSignalHandler"));
      }

      /**
      * Run the Daemon
      */
      public function run(){
         echo "Running \n";
         for($i=0; $i<500; $i++){
            $jobID = rand(0,10000000000000);

            while(count($this->currentJobs) >= $this->maxProcesses){
               echo "Maximum children allowed, waiting...\n";
               sleep(1);
            }

            $launched = $this->launchJob($jobID);
         }

         //Wait for child processes to finish before exiting here
         while(count($this->currentJobs)){
            echo "Waiting for current jobs to finish... \n";
            sleep(1);
         }
      }

      /**
      * Launch a job from the job queue
      */
      protected function launchJob($jobID){
         $pid = pcntl_fork();
         if($pid == -1){
            //Problem launching the job
            error_log('Could not launch new job, exiting');
            return false;
         }
         else if ($pid){
            // Parent process
            // Sometimes you can receive a signal to the childSignalHandler function before this code executes if
            // the child script executes quickly enough!
            //
            $this->currentJobs[$pid] = $jobID;

            // In the event that a signal for this pid was caught before we get here, it will be in our signalQueue array
            // So let's go ahead and process it now as if we'd just received the signal
            if(isset($this->signalQueue[$pid])){
               echo "found $pid in the signal queue, processing it now \n";
               $this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
               unset($this->signalQueue[$pid]);
            }
         }
         else{
            //Forked child, do your deeds....
            $exitStatus = 0; //Error code if you need to or whatever
            echo "Doing something fun in pid ".getmypid()."\n";
            exit($exitStatus);
         }
         return true;
      }

      public function childSignalHandler($signo, $pid=null, $status=null){

         //If no pid is provided, that means we're getting the signal from the system.  Let's figure out
         //which child process ended
         if(!$pid){
            $pid = pcntl_waitpid(-1, $status, WNOHANG);
         }

         //Make sure we get all of the exited children
         while($pid > 0){
            if($pid && isset($this->currentJobs[$pid])){
               $exitCode = pcntl_wexitstatus($status);
               if($exitCode != 0){
                  echo "$pid exited with status ".$exitCode."\n";
               }
               unset($this->currentJobs[$pid]);
            }
            else if($pid){
               //Oh no, our job has finished before this parent process could even note that it had been launched!
               //Let's make note of it and handle it when the parent process is ready for it
               echo "..... Adding $pid to the signal queue ..... \n";
               $this->signalQueue[$pid] = $status;
            }
            $pid = pcntl_waitpid(-1, $status, WNOHANG);
         }
         return true;
      }
   }
   $job = new JobDaemon();
   $job->run();

更多:http://blog.csdn.net/lvsmaster/article/details/6863951

分类
最新文章
最近回复
  • 常易北: 满分顶楼主!!!我也是,现在网上瞎几把扫别人云主机的智障太多了!
  • track: NAT 部分没处理,这块感觉有问题。
  • yu: 查到有用的资料很幸福!
  • boscotsang: 请问下服务器端如何控制权限让通过权限认证的客户端才能连接?现在这样只要有自编译的客户端程序都可...
  • yck932: 大侠,请问哪里有 tunnels 详细参考资料,谢谢
  • bubble: 现在linux 4.9以上的内核有个bbr的参数,用这个bbr比用锐速效果更好,可参考我的博文...
  • wang: openwrt 只有 tmp/etc/miniupnpd.conf 修改后又重置了,其他路径找...
  • wbq: 可以了 只是https透明代理如何做呢?
  • wbq: 你的这个配置需要浏览器设置代理ip+port, 现在假设不设置,只配置客户端网关为Nginx那...
  • wbq: 您好,想用Nginx做个透明代理,客户端机器配置下网关(即Nginx那台机器),客户端dns配...